I'm just wondering if it's possible to run a query to grab only a partial of a certain field based on a condition. For example my data set looks like:
"Name":"John",
"History":[
{
"speed" : 5,
"type" : "walking"
},
{
"speed" : 6,
"type" : "walking"
},
{
"speed" : 7,
"type" : "walking"
}
]
I want to run a query like:
db.getCollection('membermodel').find({
"Name":"John"
}, {
"Name":"1",
"History":"1",
//specify field condition here
"History.speed":{$gt:6}
});
will give me a result only containing the data which its speed is greater than 6:
"Name":"John",
"History":[
{
"speed" : 7,
"type" : "walking"
}
]
Thank you very much in advance. Mars