{
"city" : "ACMAR",
"loc" : [
-86.51557,
33.584132
],
"pop" : 6055,
"state" : "AL",
"_id" : "35004"
}
- db.zips.count()
29467
- db.zips.aggregate({$project:{_id:{$substr:['$city',0,1]}}},{$group:{_id:'$_id',n:{$sum:1}}},{$sort:{n:-1}})
{
"result" : [
{
"_id" : "S",
"n" : 2871
},
{
"_id" : "C",
"n" : 2692
},
{
"_id" : "M",
"n" : 2348
},
{
"_id" : "B",
"n" : 2344
},
{
"_id" : "W",
"n" : 1834
},
{
"_id" : "L",
"n" : 1738
},
{
"_id" : "P",
"n" : 1681
},
{
"_id" : "H",
"n" : 1621
},
{
"_id" : "A",
"n" : 1398
},
{
"_id" : "G",
"n" : 1304
},
{
"_id" : "R",
"n" : 1284
},
{
"_id" : "D",
"n" : 1162
},
{
"_id" : "N",
"n" : 1128
},
{
"_id" : "F",
"n" : 1091
},
{
"_id" : "E",
"n" : 1050
},
{
"_id" : "T",
"n" : 955
},
{
"_id" : "O",
"n" : 767
},
{
"_id" : "K",
"n" : 630
},
{
"_id" : "J",
"n" : 391
},
{
"_id" : "V",
"n" : 381
},
{
"_id" : "I",
"n" : 288
},
{
"_id" : "U",
"n" : 165
},
{
"_id" : "Y",
"n" : 112
},
{
"_id" : "Q",
"n" : 68
},
{
"_id" : "Z",
"n" : 48
},
{
"_id" : "3",
"n" : 22
},
{
"_id" : "6",
"n" : 20
},
{
"_id" : "4",
"n" : 19
},
{
"_id" : "5",
"n" : 15
},
{
"_id" : "2",
"n" : 13
},
{
"_id" : "7",
"n" : 10
},
{
"_id" : "9",
"n" : 8
},
{
"_id" : "8",
"n" : 3
},
{
"_id" : "0",
"n" : 3
},
{
"_id" : "X",
"n" : 2
},
{
"_id" : "1",
"n" : 1
}
],
"ok" : 1
}
- db.zips.aggregate({$project:{_id:{$substr:['$city',0,1]}}},{$group:{_id:'$_id',n:{$sum:1}}},{$match:{_id:{$in:['0','1','2','3','4','5','6','7','8','9']}}}, {$group:{_id:null,count:{$sum:'$n'}}})
{ "result" : [ { "_id" : null, "count" : 114 } ], "ok" : 1 }
- db.zips.remove({city:/^[0-9]/})
- db.zips.count()
29353
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.