Home > database >  MongoDB not saving correctly
MongoDB not saving correctly

Time:08-17

enter image description hereSo this is probably just me being stupid and forgetting something small but I've spent like 13 hours trying to fix this, so when a person joins the server mongodb is meant to kinda like make a economy profile for them and save it (contains: money, userid, bank amount) its for my server economy system. Currently nothing get's saved except for a blank value named "_id". My code is below. (and yes it's connecting to mongodb correctly) Any help would be appreceated.

the code below is the stuff in my bot.js file and the one below it is "profileSchema.js"


module.exports = async(client, discord, member) =>{
  let profile = await profileModel.create({
    userID: member.id,
    serverID: member.guild.id,
    coins: 100,
    bank: 0
  });
  profile.save();
}

const profileSchema = new mongoose.Schema({
    userID: { type: String, require: true, unique: true},
    serverID: { type: String, require: true },
    coins: { type: Number, default: 100 },
    bank: { type: Number }

})

const model = mongoose.model('ProfileModels', profileSchema);

module.exports = model;

CodePudding user response:

Can you try once with the following code?

module.exports = async(client, discord, member) =>{
  let profile = new profileModel({
    userID: member.id,
    serverID: member.guild.id,
    coins: 100,
    bank: 0
  });
  await profile.save();
}

CodePudding user response:

I don't know how do you call your member.id, but try to do:

module.exports = async(client, discord, member) =>{
  new profileModel({
    userID: member.id,
    serverID: member.guild.id,
    coins: 100,
    bank: 0
  }).save();
}

And I hope have your member.id called as message.author or something.

and what is member.guild.id tho? since your userID is a member. Are you trying to call: message.author.guild.id for member.guild.id? We really don't know. Can you show more of your code?

  • Related