Answer the question
In order to leave comments, you need to log in
How to remove a document from mongodb that contains an array of certain elements?
There is a document that contains an array.
To delete this document, you need to pass an array to mongoose with the values in exactly the same order, which is hard to guarantee. That is, the input may contain [ 'bc', ef', gh', 'ab' ], in which case it will not be removed.
When I know that this array can have a maximum of two elements, this hack works:someField: [ 'ab', 'cd', 'ef', 'gh' ]
schema.findOneAndDelete( { $or: [ { someField: [ 'ab', 'cd' ] }, { someField: [ 'cd', 'ab' ] } ] })
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question