Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!