Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda