i am having 2 documents in score collections(student)databases like below in mongodb database.
{
id: 2,
type: 'newname',
subs: [
{ time: 20, val: 'b' },
{ time: 12, val: 'a' },
{ time: 30, val: 'c' }
] }, {
id: 1,
type: 'strs',
subs: [
{ time: 50, val: 'be' },
{ time: 1, val: 'ab' },
{ time: 20, val: 'cs' }
] }
How to construct a query to get the below result
{
id: 1,
type: 'strs',
subs: [
{ time: 1, val: 'ab' },
{ time: 20, val: 'cs' },
{ time: 50, val: 'be' }
]
},
{
id: 2,
type: 'newname',
subs: [
{ time: 12, val: 'a' },
{ time: 20, val: 'b' },
{ time: 30, val: 'c' }
]
}
ie: a query for find the documents based on time and have to sort the results on 2 criteria
- by id ASC
- by sub document time ASC