Saturday 29 February 2020

Is there some 'gotchas' when doing multiple mongodb $unsets? I can't get all my fields to be deleted.

When I run the following code I'm able to have field1, field4, and field5 get removed correctly. But fields 2 and 3 don't get deleted from mongo and it's driving me crazy.It'd make sense if the first was deleted but not the rest, but to have two fields in the middle never get removed is baffling.This is literally all there is to it:const query = { $unset : [ 'field1', 'field2', 'field3', 'field4', 'field5'], $set: {'boolval1': false, 'boolval2': false, 'boolval3': false } } Device.findOneAndUpdate({'id': deviceId}, query) The resolve comes back with the document the way I want it except that field2 and field3 still exist. I've checked the spelling multiple times and have even copied/pasted.Anyone come across something like this before?

Submitted February 29, 2020 at 04:15PM by 6ThePrisoner

No comments:

Post a Comment