I'm trying to match the emailAddress
field and the page_slug
. Currently I'm using the following which matches just the about page in the modularSequence:
db.getCollection('users').find({"modularSequence.page_slug": "about"}, {"modularSequence.$": 1 })
This works and returns:
{
"_id" : ObjectId("5740c631742da6e83389abb4"),
"modularSequence" : [
{
"page_id" : "1",
"sequence" : "m_1",
"category" : "headers",
"page_slug" : "about"
}
]
}
Which it half what I want. I'm looking to return the emailAddress field as well. I've tried using this but it returns everything and multiple modular elements:
db.getCollection('users').find({$and:[{"emailAddress": 'paul@example.com'}, {"modularSequence.page_slug": "about"}, {"modularSequence": {$elemMatch: {page_slug:'about'}}}]})
[
{
"emailAddress": "paul@example.com",
"modularSequence": [
{
"page_slug": "about",
"category": "headers",
"sequence": "m_1",
"page_id": "1"
},
{
"page_slug": "contact",
"category": "content",
"sequence": "m_4",
"page_id": "2"
}
]
}
]
How do I match both the emailAddress field and the modularSequence.page_slug - only return a result if both the email address matches and the page_slug?