shivg
shivg

Reputation: 762

mongodb map/reduce or group

I have a mongodb data with candidate details

a property is qualification which is list based

doc1:  "qualification" : ["BS","Diploma"]
doc1:  "qualification" : ["BS","MS"]
doc1:  "qualification" : ["PG"]
doc1:  "qualification" : ["Diploma"]
doc1:  "qualification" : ["BS"]
doc1:  "qualification" : ["MS"]
doc1:  "qualification" : ["BS","MS","Phd"]

from this i generated top 3 qualification using mongodb map/reduce which calculates occurrences of each qualification and i filtered top 3

result is

{"BS":4,"MS":3,"Diploma":2}

but this map/reduce creates a temp collection every time, so i think it slows down my application, Can we use group statement for this scenario? or as i am using python can i generate a list of all qualification to use counter()

which is feasible and less time consuming?

Upvotes: 1

Views: 171

Answers (1)

Gates VP
Gates VP

Reputation: 45287

Can we use group statement for this scenario?

Yes.

However, the last I check the group command was single-threaded, so it may be slow on sharded configurations.

You can also take a look at the Aggregation Framework available in 2.1 and 2.2. This will also avoid the temp collection.

Your last option is to process the data in the python client. For something so simple, it's quite possible to simply loop through the data and store the results in memory.

Upvotes: 1

Related Questions