Мои документы в MongoDB:
{
"_id": {
"$oid": "5e90276937b54857689435733"
},
"user_id": "",
"nickname": "",
"platform": ""
"invites": {
"$numberInt": ""
},
"hide_game_stats": false,
"game_data": {
"player_info": {
"level": {
"value": {
"$numberInt": "96"
},
"rank_icon_url": ""
},
"platform": "battle"
},
"warzone": {
"battle_royale": {
"timePlayed": {
"$numberInt": "55789"
},
"score": {
"value": {
"$numberDouble": "202485"
}
},
"kd_ratio": {
"value": {
"$numberDouble": "1.71"
}
},
"kills": {
"value": {
"$numberInt": "217"
}
},
"games_played": {
"value": {
"$numberInt": "43"
}
},
"score_per_minute": {
"value": {
"$numberDouble": "217.77"
}
},
"contracts": {
"value": {
"$numberInt": "41"
}
},
"wins": {
"value": {
"$numberInt": "2"
}
},
"top_5": {
"value": {
"$numberInt": "7"
}
},
"top_10": {
"value": {
"$numberInt": "15"
}
},
"top_25": {
"value": {
"$numberInt": "39"
}
},
"win_rate": {
"value": {
"$numberDouble": "4.7"
}
}
},
"plunder": {
"timePlayed": {
"$numberInt": "18526"
},
"cash": {
"value": {
"$numberInt": "1158"
}
},
"score": {
"value": {
"$numberDouble": "67551"
}
},
"kd_ratio": {
"value": {
"$numberDouble": "1.99"
}
},
"kills": {
"value": {
"$numberInt": "155"
}
},
"games_played": {
"value": {
"$numberInt": "14"
}
},
"score_per_minute": {
"value": {
"$numberDouble": "218.78"
}
},
"contracts": {
"value": {
"$numberInt": "23"
}
},
"wins": {
"value": {
"$numberInt": "1"
}
},
"top_5": {
"value": {
"$numberInt": "1"
}
},
"top_10": {
"value": {
"$numberInt": "1"
}
},
"top_25": {
"value": {
"$numberInt": "1"
}
},
"win_rate": {
"value": {
"$numberDouble": "7.1"
}
}
}
},
"multiplayer": {
"timePlayed": {
"$numberInt": "180588"
},
"career_score": {
"value": {
"$numberDouble": "691843"
}
},
"kd_ratio": {
"value": {
"$numberDouble": "1.23"
}
},
"kills": {
"value": {
"$numberInt": "5345"
}
},
"total_games_player": {
"value": {
"$numberInt": "370"
}
},
"score_per_minute": {
"value": {
"$numberDouble": "229.86"
}
},
"win_rate": {
"value": {
"$numberDouble": "49.7"
}
}
}
}
}
Мне нужно только 20 документов сортировать по game_data.warzone.battle_royale.kills.value
Пожалуйста, покажите мне, как я могу это сделать
моя попытка :
findOptions := options.Find()
findOptions.SetSort(
bson.D{
primitive.E{
Key: "game_data",
Value: bson.D{
primitive.E{
Key: "warzone",
Value: bson.D{
primitive.E{
Key: "battle_royale",
Value: bson.D{
primitive.E{
Key: "kills",
Value: bson.D{
primitive.E{
Key: "value",
Value: -1,
},
},
},
},
},
},
},
},
},
},
) // set the sort function (attempt №1)
findOptions.SetSort(
bson.M{
"$match": bson.M{
"game_data.warzone.battle_royale.kills.value": -1,
},
},
) // set the sort function (attempt №2)
findOptions.SetLimit(20) // set limit to 20 docs
cursor, err := mongodb.CodHubCollection.Find(context.Background(), bson.D{}, findOptions)
if err != nil {
return err
}