简体   繁体   中英

How get the data of the nested JSON object MongoDB with node.js

I have a JSON object on MongoDB

图片

I can`t understand how to get Products by ID from the Menu?

You can read that by using the following command.
To read a single data from array:

db.dbname.findOne({'products': 
     {$elemMatch:{
          '_id': id_of_the_product_you_want_to_read
           }
     }})

You can change the parameters _id to the necessary parameter you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM