Answer the question
In order to leave comments, you need to log in
How to edit an object property in an array?
I need to edit a string that is in an object that is in an array.
I am using mongoose and javascript.
I have an array of Users, which contains 2 objects:
You need to look up the Users.Depost value based on the user ID and change it
"Users": [{
"Id": "808656561244995655",
"Rank": "owner",
"Deposit": 0,
"Joined": 1642435574167
}, {
"Id": "905432168950538282",
"Rank": "mod",
"Deposit": 0,
"Joined": 1642435574167
}],
guildDb.findOne({ GuildId: guild.id, GuildOwner: status.ownerId }, async (err, docs) => {
if (err) throw err
if (!docs) return
docs.Users.find(x => x.id === user.id).Deposit += +500
await docs.save().catch(error => console.log(error)
})
Answer the question
In order to leave comments, you need to log in
It seems to me that you should look aside populate
and lookup
not store objects in an array, but put them in a separate collection. So it will be much more convenient to manage them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question