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

javascript - How do you prevent nested queries/catches in sequelize? -

java - Could not retrieve pre-bound Hibernate session - Could not obtain transaction-synchronized Session for current thread -

ruby on rails - ActiveRecord order not working -