In MongoDB, I'm trying to write Map-Reduce functions that only save data if they meet certain criteria.
I can’t figure out how not to emit () from my gearbox. It always saves data anyway.
Here is a general example. Ignore the data context - I created this data and code solely for the purpose of this question.
Data set:
{ "_id" : ObjectId("52583b3a58da9769dda48853"), "date" : "01-01-2013", "count" : 1 } { "_id" : ObjectId("52583b3d58da9769dda48854"), "date" : "01-01-2013", "count" : 1 } { "_id" : ObjectId("52583b4258da9769dda48855"), "date" : "01-02-2013", "count" : 1 } { "_id" : ObjectId("52583b4f58da9769dda48856"), "date" : "01-03-2013", "count" : 4 }
Card Function:
A reducer that simply ignores unwanted data.
Results (value 1 was not ignored):
{ "_id" : "01-01-2013", "value" : null } { "_id" : "01-02-2013", "value" : 1 } { "_id" : "01-03-2013", "value" : 4 }
I also added a return statement to the empty statement, but I got the same results:
What I would like to have is only the following data will exist in my output collection after starting Map-Reduce. How can i do this?
{ "_id" : "01-03-2013", "value" : 4 }
source share