Since you developed the data, this is not possible.
In MongoDB, queries return the entire document. You can filter specific fields, but if the field value is an array, it stops.
When you have βarrays of objects,β you either have $slice , which is not what you want, or you will have to model your data in different ways.
In your case, the following structure will make your request possible:
{ _id: 1234, type: 'a', subs: { '123001': { val: 'a' }, '123002': { val: 'b' }, '123003': { val: 'c' } } }
Notice how I changed subs to a JSON object instead of an array. Now you can execute the following query and get only the time you are looking for:
find( { _id: 1234 }, { 'subs.123002': 1 } )
The obvious trade-off here is that you have to change the way you use the document. You cannot use $push on subs , you cannot request for {'subs.time': 1234} , instead you should request {'subs.1234': { $exists:true} } .
source share