I'm currently in the process of updating an object within an array found in a document
"state": [],
"users": [{
"ready": false,
"_id": {
"$oid": "5fb810c63af8b34180912014"
},
"user": {
"$oid": "5f81eb91d537dc3baf443a84"
},
"calification": 0
}, {
"ready": false,
"_id": {
"$oid": "5fb810ca3af8b34180912015"
},
"user": {
"$oid": "5fa6f98f15e96c1125b905a9"
},
"calification": 0
}],
"test": {
"$oid": "5f986af2baa88b2d30760961"
},
"__v": 1
}
Here is the function I am using for this task:
updateUserState = async function(game_id,username){
var user_id = '5fb7fae0c28f1d33a99b877e';
await Game.findOneAndUpdate({_id: game_id, users: {$elemMatch: {user: user_id}}},
{$set: { ready: true}},
{'new': true, 'safe': true, 'upsert': true});
}
However, I encountered the following error:
(node:16768) UnhandledPromiseRejectionWarning: MongoError: E11000 duplicate key error collection: myproject.games index: _id_ dup key: { _id: ObjectId('5fb810c63af8b34180912013') }
I am puzzled as to why it is specifying that the key is a duplicate