2
{ "userID" : 1, "amount" : 2, "date" : ISODate("2012-04-03T20:53:19.490Z") }
{ "userID" : 1, "amount" : 4, "date" : ISODate("2012-04-03T20:53:19.490Z") }
{ "userID" : 2, "amount" : 4, "date" : ISODate("2012-04-03T20:53:19.490Z") }
{ "userID" : 3, "amount" : 1, "date" : ISODate("2012-04-03T20:53:19.490Z") }
{ "userID" : 1, "amount" : 2, "date" : ISODate("2012-04-03T20:53:19.490Z") }

I'm performing incremental Map/Reduce operation where when I'm counting the sum of purchases. The m/r functions are very simple so I'm not writing it here.

    MapReduceCommand cmd = new MapReduceCommand(coll, map, reduce, "result",  MapReduceCommand.OutputType.MERGE, null);

The result will be the following. Which is perfect:

{ "_id" : 1, "value" : 8 }
{ "_id" : 2, "value" : 4 }
{ "_id" : 3, "value" : 1 }

If user with userIF 4 will be added to system,my incremental map reduce would take care of it and new row will be added to result collection.

Problem: if userID 2 will be deleted from system, his row would still remain in result collection. How can I take care of such stale values when using incremental Map reduce?

1
  • 1
    Considering Mongo's de-normalized nature I'd imagine your solution is going to be pretty mundane and basically just involves deleting that document in the process of deleting the user.
    – clexmond
    Apr 4, 2012 at 1:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.