mongodb - How can I aggregate collection and group by field count -


I have a collection of users who looks like this:

  {"_id ":" Email ":" email@email.com "," OGP ": [Big Nest compilation ... {}, {}, {}}" created ": ObjectDid (" 54380a817a4b612a38e87613 ")," Email ":" "Country": "America", "City": "Seattle", "Longitude": 123, "Latitude": "02-228T23: 10: 07Z"), "o_id": ObjectId ("5438096f7a4b612a38e445f4") "Geo" : 123}}  

I want to get all the user space and want to group them through the country and the total. Something like this:

[[Country: "US", total: 250,000}, {country: "GB", total: 150,000}, ...]

Currently I'm grabbing all the documents and parsing it on the server:

  db.users.find ({'geo.country': {$ ne: null}, 'Geo.city': {$ ne: null}}, {'geo.country': 1}, function (error, doctor) {var data; doc = _.groupBy (doctor, function (equals) {return equal. Geo.country;}); data = []; back _.each (doctor, function (item, key, obez) {return data. Push ([key, oz [key] length]);})}} ;  

There are 600,000+ documents with this problem and it takes about 1 minute to execute the query. Will "overall" work speed up this query? If so, how do I do this?

should do this:

  db.myCollection.aggregate ( [{"$ Group": {_id: "$ geo.country", Calculation: {$ sum: 1}}}])  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -