For example, there is a set of data:
name: 'food',
data: {
fruit: [
{
name: 'apple',
stock: 10
},
{
name: 'pear',
stock: 66
}
...
]
}
db.col.find({'data.fruit.stock': 66}, {data.fruit.stock: 1})
The query is the entire data.fruite
;
Q1: Is there any way to get only the data queried by the filter? What if the document object size is relatively large?
Q2: Is this a feature of Mongodb? After matching the filter condition, is the entire document object returned?
Q3: Is there any API documentation in this area that I can refer to?
The question asked by the questioner is actually related to the trade-off between Data Model and business query.
1. MongoDB returns basically the unit of document each time. If the document contains an array (Array), all arrays need to be returned;
2. As the subject wishes, if you want to follow the query conditions and just return the data in the array that meets the conditions, you can consider
/q/10...
For reference.
Love MongoDB! Have Fun!
------------------------Gorgeous separator--------------------- ----------
MongoDB Chinese community has many offline activities, please click below:
2017 Huashan Sword Discussion|MongoDB Chinese Community
Hangzhou Station is coming in March! ! ! Interested friends please sign up quickly! ! !
It will indeed return the stock of data.fruit data; but it can also return the stock of conditions, but you need to know the index number of stock in the fruit array.
That’s
Reference (mongodb version 3.4):
https://docs.mongodb.com/manu...
https://docs.mongodb.com/manu...