1

Can someone help me with a solution to find an array object inside the MongoDB document, I've tried a couple of methods but am still not able to get the object that I need I'm trying to query based on the user data e.g finding using user email and name, here is the document that I want to find array in the document.

{
"_id": "lfe78vlwncr",
"images": [],
"location": [28.1339088, -26.2098077],
"_p_category": "Category$ZjfUGGzbNb",

"image": "5d4663900459815806965d8af5392190_image.jpg",
"imageName": "5d4663900459815806965d8af5392190_image.jpg",
"imageThumb": "5d4663900459815806965d8af5392190_image.jpg",
"isHead": "1",
"storeNumber": null,
"twitter": null,
"superUser": null,
"youtube": null,

"user": {
    "email": "[email protected]",
    "name": "john"
},
"_created_at": "2022-03-15T08:17:46.769Z",

"status": "Approved",
"_wperm": ["*"],
"_rperm": ["*"],
"_acl": {
    "w": "true",
    "r": "true"
},
"bIsSales": "true",
"_updated_at": "2022-03-17T05:06:38.425Z",
"bShow": true,

"imageFour": "49217bd1ccf227f010562be0b9e0b889_image.jpg",
"imageThree": "998866aa6707b520f8a6d214351b6256_image.jpg",
"imageTwo": "a394516d65948af07033ac8812d225b8_image.jpg",

}

here is what I tried so far yet still not working.

db.collection("Place")
.find({

    user: {
        email: req.body.userEmail,
        name: req.body.userName
    }
})
.toArray(function(err, result) {
    if (err) throw err;

    res.json(result);
});

1 Answer 1

1

Try it like this:

db.collection("Place")
.find({
  'user.email': req.body.userEmail,
  'user.name': req.body.userName
})
.toArray(function(err, result) {
    if (err) throw err;

    res.json(result);
});

Playground

Sign up to request clarification or add additional context in comments.

2 Comments

That didn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.