Is there a query that receives multiple fields and returns which one exists in the collection? For example, if a collection has only:
{id : 1} {id : 2}
And I want to know which one [{id : 1} , {id : 3}]exists in it, then the result will be similar to [{id : 1}].
[{id : 1} , {id : 3}]
[{id : 1}]
You are looking for $ in-operator .
db.collection.find({ id: { $in: [ 1, 3 ] } });
This will give you any documents where the id field (other than the special field _id) is 1 or 3. When you need only the id field values, and not all documents:
_id
db.collection.find({ id: { $in: [ 1, 3 ] } }, { _id: false, id:true });
, key with value , , $or.
key with value
$or
id _id .
id
$ , :
db.collection.find({$or:[{"id":1},{"id":3}]},{"_id":0,"id":1})
_id, :
db.collection.find({$or:[{"_id":ObjectId("557fda78d077e6851e5bf0d3")},{"_id":ObjectId("557fda78d077e6851e5bf0d5")}]}