0

This is just an example code... I have managed to get to the third embeded document using .$ , but not further... How do I query the fourth nested part(article headings)?

  {
    "bookTitle": "MongoDB",
    "_id": ObjectId("530dea1d2dbf280000533b60"),
    "bookChapters": [{
    "chapterTitle": "chapterTitle",
    "_id": ObjectId("530dea1d2dbf280000533b61"),
    "chapterArticles": [{
        "articleTitle": "articleTitle",
        "_id": ObjectId("530dea1d2dbf280000533b62"),
        "articleHeadings": [{
            "headingTitle": "headingTitle",
            "_id": ObjectId("530dea1d2dbf280000533b63")
        }]
    }]
    }],
    "__v": 0
}

1 Answer 1

1

You can use $elemMatch to match nested element in array. I used headingTitle to match here. Query will be like following-

db.collection.find({
    "bookChapters": {
    "$elemMatch": {
        "chapterArticles": {
            "$elemMatch": {
                "articleHeadings": {
                    "$elemMatch": {
                        "headingTitle": "headingTitle"
                    }
                }
            }
        }
    }
    }
})

If you want to convert it to mongo c# driver then you can refer this

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

Comments

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.