i have a document which has subdocument array in it(size is 6), then i remove 5 element at the same time, it perfectly updates array, but cant find the document after updated, here the code to update it
await gameRoom.findOneAndUpdate({ 'players._id': currentUser._id }, { $pull: { players: { _id: currentUser._id } } }, { 'new': true },
(err, docc) => {
console.log('currentUser id ' + currentUser._id + ' time ' + new Date().toUTCString());
console.log('doc ' + JSON.stringify(docc));
if (err) console.log('error at logging out gameRoom.findOne ', '\n ' + err);
else if (docc == null) console.log('how it can be null');
});
and this is result
currentUser id 5eb285720105534970994c92 time Wed, 06 May 2020 09:38:26 GMT
doc null
how it can be null
currentUser id 5eb2856a0105534970994c89 time Wed, 06 May 2020 09:38:26 GMT
doc null
how it can be null
currentUser id 5eb2856f0105534970994c8f time Wed, 06 May 2020 09:38:26 GMT
doc IsNotNull
currentUser id 5eb2856d0105534970994c8c time Wed, 06 May 2020 09:38:26 GMT
doc null
how it can be null
currentUser id 5eb285750105534970994c96 time Wed, 06 May 2020 09:38:26 GMT
doc IsNotNull
currentUser id 5eb285680105534970994c85 time Wed, 06 May 2020 09:38:30 GMT
doc IsNotNull
so firstly i pull 5 element from array , then i pull last one as you can see in result, all of them removed from array perfecly with update, but someof them cant reach the docc they updated how is this possible ?