javascript - Query subdocuments MongoDB Node.JS -


i have collection of objects have sub dictionary contains data given institution, identified provider_id.

how can query collection, products , return produce contain given provider id?

  "natl_total_cost": 1.27478784e9,   "natl_average": 8338.487,   "natl_report_count": 152880,   "name": "wax",   "provider_cost_dict": {      "340008": {         "report_count": 181,         "total_cost": 1335465,         "average_cost": 7378.26      },      "340001": {         "report_count": 643,         "total_cost": 5026724,         "average_cost": 7817.6113      }, ... 

how query of products returns products contain given provider id in provider_cost_dict?

you can use $exists operator

db.getcollection('yourcoll').find({"provider_cost_dict.340008": { $exists: true }}) 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -