Mongodb: return matched filters when using $ or find ()

Suppose I make a request in Mongodb, like this

db.user.find({$or : [{"field1" : "abc"}, {"field2" : "def"}, {"field3" : "ghi"}]}) 

And a number of documents are returned. What is the easiest way to find out which of (or several) of the three filters corresponds to each returned document? "The easiest", I do not want to add more find () executions.

Thank.

+4
filter find mongodb match
Jul 08 2018-11-22T00:
source share
1 answer

There is no way to solve this problem at the MongoDB query level. You probably want to run separate requests instead of a single large $ or request to solve your problem.

0
Jul 09 2018-11-11T00:
source share



All Articles