Answer the question
In order to leave comments, you need to log in
How to get an object from an array of objects by id in mongodb?
In my mongo database, data is stored in this form
[
{
"product_id": [],
"_id": "60eebb77c8c95045c4231d50",
"name": "phone",
"__v": 0
},
{
"product_id": [],
"_id": "60eebb95c8c95045c4231d52",
"name": "notebook",
"__v": 0
}
]
{
"product_id": [],
"_id": "60eebb95c8c95045c4231d52",
"name": "notebook",
"__v": 0
}
Answer the question
In order to leave comments, you need to log in
let result = arr.find(x => x._id === '60eebb95c8c95045c4231d52');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question