When learning real-time analysis methods using MongoDB, there seems to be a pretty standard way to do the sums, but nothing happens in terms of more complex aggregation. Some things that helped ...
The basic approach for performing amounts is to atomically increase the document keys for each new entry that is included in the system to cache common queries:
Stats.collection.update({"keys" => ["a", "b", "c"]}, {"$inc" => {"counter_1" => 1, "counter_2" => 1"}, "upsert" => true);
This does not work for aggregates other than sums. My question is: can something like this do for medium , min and max in mongodb?
Say you have a document like this:
{ :date => "04/27/2011", :page_views => 1000, :user_birthdays => ["12/10/1980", "6/22/1971", ...] # 1000 total }
Could you do some atomic or optimized / operative operation that grouped birthdays into something like that?
{ :date => "04/27/2011", :page_views => 1000, :user_birthdays => ["12/10/1980", "6/22/1971", ...], # 1000 total :average_age => 27.8, :age_rank => { "0 to 20" => 180, "20 to 30" => 720, "30 to 40" => 100, "40 to 50" => 0 } }
... just like you can do Doc.collection.update({x => 1}, {"$push" => {"user_birthdays" => "12/10/1980"}}) to add that something into an array, and not load the document, can you do something similar to average / aggregate the array? Is there anything in this direction that you use for real-time aggregation?
MapReduce is used for batch processing jobs, I am looking for templates for something like real-time conversion for:
- Average values : every time you click a new element on an array in mongodb, what is the best way to average these values ββin real time?
- Grouping : if you group the age for 10 year brackets and you have an array of ages, how could you optimally update the score for each group as you update the document with a new age? let's say an array of age will be constantly pushed / pulled out.
- Min / Max : what are the ways to calculate and save the minimum / maximum array of these ages in this document?