如何调整 MongoDB 查询以按降序获取输出
How to tweak the MongoDB query to get the output in descending order
我正在处理转换为 JSON.In 此查询的 OSM 文件,我正在尝试获取 .json file.I 中所有便利设施的计数,需要知道如何使输出反向。
查询:-
db.char.aggregate([{"$match":{"amenity":{"$exists":1}}}, {"$group":{"_id":"$amenity",
"count":{"$sum":1}}}, {"$sort":{"count":1}}, {"$limit":100}])
当前输出:-
{ "_id" : "bar", "count" : 1 }
{ "_id" : "fitness_center", "count" : 1 }
{ "_id" : "fountain", "count" : 1 }
{ "_id" : "studio", "count" : 1 }
{ "_id" : "telephone", "count" : 1 }
{ "_id" : "nightclub", "count" : 1 }
{ "_id" : "shelter", "count" : 1 }
{ "_id" : "courthouse", "count" : 1 }
{ "_id" : "kindergarten", "count" : 1 }
{ "_id" : "doctors", "count" : 1 }
{ "_id" : "laboratory", "count" : 1 }
{ "_id" : "toilets", "count" : 2 }
{ "_id" : "community_centre", "count" : 2 }
{ "_id" : "embassy", "count" : 2 }
{ "_id" : "fire_station", "count" : 2 }
{ "_id" : "townhall", "count" : 2 }
{ "_id" : "prison", "count" : 2 }
{ "_id" : "clinic", "count" : 2 }
{ "_id" : "pub", "count" : 3 }
{ "_id" : "grave_yard", "count" : 3 }
{"$sort":{"count":-1}}
在排序部分应该做你!
我正在处理转换为 JSON.In 此查询的 OSM 文件,我正在尝试获取 .json file.I 中所有便利设施的计数,需要知道如何使输出反向。
查询:-
db.char.aggregate([{"$match":{"amenity":{"$exists":1}}}, {"$group":{"_id":"$amenity",
"count":{"$sum":1}}}, {"$sort":{"count":1}}, {"$limit":100}])
当前输出:-
{ "_id" : "bar", "count" : 1 }
{ "_id" : "fitness_center", "count" : 1 }
{ "_id" : "fountain", "count" : 1 }
{ "_id" : "studio", "count" : 1 }
{ "_id" : "telephone", "count" : 1 }
{ "_id" : "nightclub", "count" : 1 }
{ "_id" : "shelter", "count" : 1 }
{ "_id" : "courthouse", "count" : 1 }
{ "_id" : "kindergarten", "count" : 1 }
{ "_id" : "doctors", "count" : 1 }
{ "_id" : "laboratory", "count" : 1 }
{ "_id" : "toilets", "count" : 2 }
{ "_id" : "community_centre", "count" : 2 }
{ "_id" : "embassy", "count" : 2 }
{ "_id" : "fire_station", "count" : 2 }
{ "_id" : "townhall", "count" : 2 }
{ "_id" : "prison", "count" : 2 }
{ "_id" : "clinic", "count" : 2 }
{ "_id" : "pub", "count" : 3 }
{ "_id" : "grave_yard", "count" : 3 }
{"$sort":{"count":-1}}
在排序部分应该做你!