I have the following situation: I need to query a document with a projection that returns only the first element of a list. But this list is inside another list, and that other list is inside an object that is inside another object in a document in MongoDB, more or less like the following example:
{
"items": {
"item": [
{
"items": {
"item": [
{
"cell": [
{
"value": "a"
},
{
"value": "b"
},
{
"value": "c"
}
]
}
]
}
}
]
}
}
My goal is to search for value: "a" with a projection that ignores the other values. That is, my projection should return this:
{
"items": {
"item": [
{
"items": {
"item": [
{
"cell": [
{
"value": "a"
}
]
}
]
}
}
]
}
}
The problem is that I have tried all possible alternatives: I used $ elemMatch, $ and $ slice to return only the first element, but I can not mount a query that does this because of the complexity of the document. I'm using MongoDB 3.2.
If you need more information I update here. Anyway thank you all right away!