Is it possible in mongodb do a query for find documents where the field is an array and all its elements satisfy a condition?
For example:
[
{
"_id": ObjectId("53d63d0f5c7ff000227cd372"),
"works": [
{
"code": "A001",
"items": [
{
"_id": "534664b081362062015d1b77",
"qty": 6
},
{
"_id": "534ba71f394835a7e51dd938",
"qty": 5
}
],
"name": "Cambiar bombilla",
"price": 100,
"Date": "2014-07-30T09:43:17.593Z",
"TechnicianId": "538efd918163b19307c59e8e",
"percent": 2,
"_id": ObjectId("53d63d0f5c7ff002207cd372")
},
{
"code": "A001",
"name": "Cambiar bombilla",
"price": 100,
"type": "Bombillas",
"TechnicianId": "538efd918163b19307c59e8e",
"date": "2014-07-31T13:36:34.019Z",
"orderId": "53d63d0f5c7ff000007cd372",
"_id": ObjectId("53da466568c26f8a72b50fcb"),
"percent": 66
}
]
},
{
"_id": ObjectId("53d63d0f5c7ff000007cd372"),
"works": [
{
"code": "A001",
"items": [
{
"_id": "534664b081362062015d1b77",
"qty": 6
},
{
"_id": "534ba71f394835a7e51dd938",
"qty": 5
}
],
"name": "Cambiar bombilla",
"price": 100,
"Date": "2014-07-30T09:43:17.593Z",
"TechnicianId": "538efd918163b19307c59e8e",
"percent": 2,
"_id": ObjectId("53d63d0f5c7ff002207cd372")
},
{
"code": "A001",
"name": "Cambiar bombilla",
"price": 100,
"type": "Bombillas",
"TechnicianId": "538efd918163b19307c59e8e",
"date": "2014-07-31T13:36:34.019Z",
"orderId": "53d63d0f5c7ff000007cd372",
"_id": ObjectId("53da466568c26f8a72b50fcb"),
}
]
}
]
I need to find the documents like first document because in works field his subdocuments have percent, but in the second document, works array at second position doesnt have percent.