mongodb find all records with subdocument id equals to -
i have next collection records:
> db.products.find(objectid("53a9a6aad901f2961403fc9b")).pretty() { "_id" : objectid("53a9a6aad901f2961403fc9b"), "code" : "n39", "name" : { "en-uk" : "n39" }, "weight" : [ 90 ], "collectionid" : objectid("53a9a6a8d901f2961403fbe2"), "fabric_composition" : [ { "fabricid" : objectid("53a9a6a9d901f2961403fc69"), "value" : 70 } { "fabricid" : objectid("53a9a6a9d901f2961403fc6a"), "value" : 30 } ], "visible" : "true", "manufacturer" : "53a859d9d901f2e8f81ac83b" }
and
> db.fabric.find().pretty() { "_id" : objectid("53a9a6a9d901f2961403fc69"), "name" : [ { "en-uk" : "recycled organic cotton" } ] } { "_id" : objectid("53a9a6a9d901f2961403fc6a"), "name" : [ { "en-uk" : "recycled polyester" } ] }
how query mongodb collection products
list products have fabric_composition objectid
recycled organic cotton
example?
any advice much appreciated
you need utilize use dot notation query subdocuments:
db.products.find({ "fabric_composition.fabricid" : objectid("53a9a6a9d901f2961403fc69") });
this query homecoming documents have @ to the lowest degree 1 sub-document fabricid
you're looking for.
mongodb mongodb-query
No comments:
Post a Comment