mongodb queries find total number of cities in the database -


hi have huge data contains information below:

  { "_id" : "01011", "city" : "chester", "loc" : [ -72.988761, 42.279421 ], "pop" : 1688, "state" : "ma" }   { "_id" : "01012", "city" : "chesterfield", "loc" : [ -72.833309, 42.38167 ], "pop" : 177, "state" : "ma" }   { "_id" : "01013", "city" : "chicopee", "loc" : [ -72.607962, 42.162046 ], "pop" : 23396, "state" : "ma" }   { "_id" : "01020", "city" : "chicopee", "loc" : [ -72.576142, 42.176443 ], "pop" : 31495, "state" : "ma" } 

i want able find number of cities in database using mongodb command. database may have more 1 recored has same city. example above.

i tried:

  >db.zipcodes.distinct("city").count(); 2015-04-25t15:57:45.446-0400 e query    warning: log line attempted (159k) on max size (10k), printing beginning , end ... typeerror: object agawam,belchertown ***data*** has no method 'count' 

but didn't work me.also did this:

   >db.zipcodes.find({city:.*}).count();    2015-04-25t16:00:01.043-0400 e query    syntaxerror: unexpected token . 

but didn't work , if work count redundant data (city). idea?

instead of doing

db.zipcodes.distinct("city").count();  

do this:

db.zipcodes.distinct("city").length;  

and there aggregate function, may you.

i have found 1 example on aggregate (related query).

if want add condition, refer $gte / $gte (aggregation) and/or $lte / $lte (aggregation)

see, if helps.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -