/* 1 */{"_id": ObjectId ("55e542cd7f8b9aca2b8b4568"), "game_id": 1103, "tags": [{"T ag_id ":", "Name": "West Tour", "Rank": Ten,}, {"tag_id": 123, " Name ":" Online Game "," Rank ": 1,},]," Time_sort ": 1435306}/* 2 */{" _id ": ObjectId (" 55dd8fe67f8b9 A25528b64f7 ")," game_id ": 6408," tags ": [{" tag_id ":" "Name": "White Collar favorites", "Rank": "tag_id": 123, "name": "Online Game", "Rank": 2,}, ], "Time_sort": 1411574}/* 3 */{"_id": ObjectId ("55dd91197f8b9a25528b9585"), "game_id": 18498, "tags" : [{"tag_id": +, "name": "Turn-based", "Pc_rank": 120,}, { "tag_id": 123, "name": "Online Game", "Rank": 3,},], "Time_sort": 1437385}
Now just want to through the online game label Rank Sort, the statement should be how to write
Reply content:
/* 1 */{"_id": ObjectId ("55e542cd7f8b9aca2b8b4568"), "game_id": 1103, "tags": [{"T ag_id ":", "Name": "West Tour", "Rank": Ten,}, {"tag_id": 123, " Name ":" Online Game "," Rank ": 1,},]," Time_sort ": 1435306}/* 2 */{" _id ": ObjectId (" 55dd8fe67f8b9 A25528b64f7 ")," game_id ": 6408," tags ": [{" tag_id ":" "Name": "White Collar favorites", "Rank": "tag_id": 123, "name": "Online Game", "Rank": 2,}, ], "Time_sort": 1411574}/* 3 */{"_id": ObjectId ("55dd91197f8b9a25528b9585"), "game_id": 18498, "tags" : [{"tag_id": +, "name": "Turn-based", "Pc_rank": 120,}, { "tag_id": 123, "name": "Online Game", "Rank": 3,},], "Time_sort": 1437385}
Now just want to through the online game label Rank Sort, the statement should be how to write
Pipeline query and then use unwind to play with tags, and then sort
"tags" : [ { "tag_id" : 28, "name" : "白领最爱", "rank" : 20, }, { "tag_id" : 123, "name" : "网游", "rank" : 2, }, ],
The two elements inside the tags array have the rank field, do you want to sort by the first rank or the second rank?