My user schema has an empty array called games. I want to push different objects to that array that contain two properties. The problem is that instead of pushing like nameObj: { name: ‘name’, win: 0 }, what ended to be pushed is between another { }. I don’t know how should I push properly.
Here’s my method.
app.get('/update-user', (req, res) => {
User.findOneAndUpdate(
{ username: 'katana_user' },
{ $push: { games: { sfv: { name: videogames.sfv.name, wins: 0 } } } }, (err, success) => {
if (err) {
console.log(err);
} else {
console.log(success);
}
});
});
I’d appreciate any help possible!