Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (19.9k points)

I am working with a collection of users like so

    "_id" : ObjectId("5dc822c6547b8500340b2c34"), 

    "firstName" : "SomeFirstName", 

    "lastName" : "SomeLastName", 

    "uniqueId" : "HF2134fGA"


    "_id" : ObjectId("b80340b2c34522c65450dc87"), 

    "firstName" : "AnotherFirstName", 

    "lastName" : "AnotherLastName", 

    "uniqueId" : "4F21fGH3A"


Also a list of Object like so

[{name: "Name", id:"4F21fGH3A"}, {name: "Name", id:"21fG34HFA"}]

I would like to return every documents where an id contained in the objects array matches a uniqueId in the collection of users.

1 Answer

0 votes
by (25.1k points)

The $in operator and a map to remove the unwanted elements on the server seems to do the trick

{ "uniqueId": {$in: ["4F21fGH3A", "21fG34HFA"]} } 

Browse Categories