Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
Mongoose not saving elements in Object Array?

I'm trying to make a RPG Discord Bot, where you can level skills, sell items, etc. Recently, a friend of mine refactored all the code. Everything is working, besides the start command:

Before the refactor, it'd save everything correctly. Afterwards, it didn't save the maxLevel property for any skill and began saving ObjectID properties.

Skills/start.js


    await new client.database.user({
      userID: interaction.user.id,
      inventory: [],
      coins: 250,
      skills: [
        {
          name: 'Strength',
          level: 1,
          exp: 0,
          maxLevel: 50,
        },
        {
          name: 'Agility',
          level: 1,
          exp: 0,
          maxLevel: 50,
        },
        {
          name: 'Knowledge',
          level: 1,
          exp: 0,
          maxLevel: 50,
        },
        {
          name: 'Trading',
          level: 1,
          exp: 0,
          maxLevel: 50,
        },
        {
          name: 'Challenge',
          level: 1,
          exp: 0,
          maxLevel: 5,
        },
        {
          name: 'Hunting',
          level: 1,
          exp: 0,
          maxLevel: 50,
        }
      ],
      mobsKilled: 0,
      bossesKilled: 0,
      created: moment().format('DD/MM/YYYY'),
      heavenDifficulty: Math.floor(Math.random() * 9 + 1),
    }).save();

Schemas/User.js

import mongoose from 'mongoose';

const userSchema = mongoose.Schema({
  userID: String,
  guild: {
    guildID: String,
    guildName: String,
    position: String
  },
  inventory: [{ name: String, amount: Number }],
  coins: Number,
  skills: [{ name: String, level: Number, exp: Number }],
  mobsKilled: Number,
  bossesKilled: Number,
  created: String,
  heavenDifficulty: Number,
  isPremium: Boolean,
  premium: {
    since: String,
    sinceTS: String, //TS = Timestamp
    tier: String
  }
});

const UserSchema = mongoose.model('users', userSchema);

Also, I do know, that the premium properties are empty. This is because I want to add them to the database, when someone becomes a premium member and not when they start their journey.

Edit: This is what it's returning (all undefined properties should be the maxLevel property) Attachment:

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

"Afterwards, it didn't save the maxLevel property..."

Is the issue occurring because you need to add a maxLevel property to your database schema?

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda