I've tried very hard to read the documentation on finding and sorting but haven't had luck. I can change my document structure if it's not suitable for the operation I want to do but I'd prefer my current structure.
All users have names and an array of skills, each which have names and associated skill levels. All users have skill levels in every skill.
Here's my structure:
{
"name": "Alice",
"skills": [
{
"name": "gardening",
"level": 10
},
{
"name": "shopping",
"level": 7
}
]
},
{
"name": "Bruce",
"skills": [
{
"name": "gardening",
"level": 5
},
{
"name": "shopping",
"level": 10
}
]
}
And I have many of these objects, each of them I'll call Users. I'd like to sort Users by their Gardening skill level.
I know I can access level 10 Users, regardless of which skill they're level 10 in, with a find query:
{ 'skills.level' : 10 }
But I want to sort users by their Gardening skill level, with a sort command like:
{ "skills.gardening.level" : 1 }
But this doesn't work because of my current structure.
Do I need to change my structure in order to sort like this or can I make this work?