Hi there,
I’m facing a rather interesting issue.
The following query does not update the document.
collection.findOneAndUpdate
(
{
foo: {'$in': ['bar']},
_id: 'someStringId',
'baz._id': 'someOtherStringId',
},
{$set: {'baz.$.boolean': false}},
{returnOriginal: false},
callback
)
After some investigation, it turned out that $in
seems to be the root cause of the issue. As I didn’t really needed that (usually there is only one element in the array), I’ve replaced it with $elemMatch
- and the document is now updated successfully.
collection.findOneAndUpdate
(
{
foo: {$elemMatch: {$eq: 'bar'}},
_id: 'someStringId',
'baz._id': 'someOtherStringId',
},
{$set: {'baz.$.boolean': false}},
{returnOriginal: false},
callback
)
I’d like to understand the root cause of the issue, so feel free to chip in if you have a sensible explanation.
Please note that the server version is 3.0.15 and I’m using the official NodeJS driver (version 3.3.2).
Cheers