Home > database >  How I can find object ID of MMT4 by nodeJS and mongoDB?
How I can find object ID of MMT4 by nodeJS and mongoDB?

Time:09-23

How I can find object ID of MMT4 by nodeJS and mongoDB ? enter image description here

Thank you for your help ❤️

CodePudding user response:

Hi I worked on your question and if you are using mongodb and nodejs you can do the following stpes:

  1. using $match and $unwind aggregations to find the object that match with title MMT4:

    db.collection.aggregate([{$unwind: "$children"}, {$match: {"children.title": "MMT4"}}])

    Notice: I wrote the above syntax in mongodb shell you can write it in JS with mongoose library.

  2. the result is an object with children array that contain just MMT4 object. you can iterate in this single element array using JS to get _id of the MMT4

referece: click here

  • Related