I looked through several articles and examples and have not yet found an effective way to make this SQL query in MongoDB (where there are millions of documents rows )
First try
(for example, from this almost duplicated question - Mongolian equivalent of SQL SELECT DISTINCT? )
db.myCollection.distinct("myIndexedNonUniqueField").length
Obviously, I got this error, since my data array is huge
Thu Aug 02 12:55:24 uncaught exception: distinct failed: { "errmsg" : "exception: distinct too big, 16mb cap", "code" : 10044, "ok" : 0 }
Second attempt
I decided to try and make a band
db.myCollection.group({key: {myIndexedNonUniqueField: 1}, initial: {count: 0}, reduce: function (obj, prev) { prev.count++;} } );
But I got this error message:
exception: group() can't handle more than 20000 unique keys
Third attempt
I haven't tried it yet, but there are a few suggestions that include mapReduce
eg.
AND
There seems to be a porting request to GitHub fixing the .distinct method to mention that it should only return an invoice, but it is still open: https://github.com/mongodb/mongo/pull/34
But at that moment I thought it was worth asking here what is the last on this subject? Should I upgrade to SQL or another NoSQL database for different accounts? or is there an effective way?
Update:
This comment on MongoDB white papers is not encouraging, is this true?
http://www.mongodb.org/display/DOCS/Aggregation#comment-430445808
Update2:
The new aggregation structure seems to be responding to the above comment ... (MongoDB 2.1 / 2.2 and above, the preview is available, not for production)
http://docs.mongodb.org/manual/applications/aggregation/