I have the following database in mongodb:
{
"notebook":
{"Year20162017":
{"Cards": [
{"Card": {
"Number": 1,
"Player": {
"Code": "a",
"Team": {
"Name": "ABC"
}
}
}},
{"Card": {
"Number": 18,
"Player": {
"Code": "c",
"Team": {
"Name": "GHI"
}
}
}},
{"Card": {
"Number": 35,
"Player": {
"Code": "b",
"Team": {
"Name": "DEF"
}
}
}}
]}}}
I need to sort by the number of each card, so I tryed to do it using aggregations:
db.cromos1617.aggregate([
{$unwind: {"notebook.Year20162017.Cards"}},
{$sort: {"notebook.Year20172017.Cards.Card.Number": 1}}
])
First I used unwind to separate the array of Cards, then I sorted the elements by the number of each card, but it didn't worked well, it gave me:
2018-01-04T18:44:09.593+0000 E QUERY [thread1] SyntaxError: missing : after property id @(shell):2:41
How it is done properly?