Posts

Showing posts with the label mongodb-query

How to make lookup between two collections when an item in an array exists in the other collection?

Image
Clash Royale CLAN TAG #URR8PPP How to make lookup between two collections when an item in an array exists in the other collection? In Lookup with a pipeline, I would like to get the linked records from an array in the parent document. // Orders [{ "_id" : ObjectId("5b5b91a25c68de2538620689"), "Name" : "Test", "Products" : [ ObjectId("5b5b919a5c68de2538620688"), ObjectId("5b5b925a5c68de2538621a15") ] }] // Products [ { "_id": ObjectId("5b5b919a5c68de2538620688"), "ProductName": "P1" }, { "_id": ObjectId("5b5b925a5c68de2538621a15"), "ProductName": "P2" } , { "_id": ObjectId("5b5b925a5c68de2538621a55"), "ProductName": "P3" } ] How to make a lookup between Orders and Products when Products field is an array ! Products I tried this query db.getCollection...