mongodb - Why does MapReduce return _id and value parameters? -



mongodb - Why does MapReduce return _id and value parameters? -

i need create map cut down function search set of conditions within document , if met, homecoming entire document (or create new table documents match). next simplified illustration of need maintain in mind actual documents have more them.

lets have 2 documents:

document #1:

{ "_id": objectid("542ec1a91d40cafd58b928b4"), "billing": { "category1": { "0": { "mode": "email", "email": { "0": "test@what.com" } } }, "category2": { "0": { "mode": "email", "email": { "0": "who@cares.net" } } } } }

document #2:

{ "_id": objectid("542ec1a91d40cafd58b928b4"), "billing": { "category1": { "0": { "mode": "email", "email": { "0": "test@what.com" } } }, "category2": { "0": { "mode": "email" } } } }

i need determine documents have elements mode value of "email" not have corresponding email element. i've got far:

var mapfunction = function() { for(var bkey in this.billing) { (var bsubkey in this.billing[bkey]) { var modeisemail = (this.billing[bkey][bsubkey].mode == 'email'); var emailelementismissing = (typeof this.billing[bkey][bsubkey].email == 'undefined'); if (modeisemail && emailelementismissing) { var newdoc = this; delete newdoc._id; emit('document', newdoc); } } } } var reducefunction = function(documentkey, badrecord) { homecoming badrecord; } db.cust.mapreduce(mapfunction, reducefunction, { out:"test_reduce"})

while technically works annoyed , confused construction of output. output looks like:

"_id" : "document", "value" : { "billing": { "category1": { "0": { "mode": "email", "email": { "0": "test@what.com" } } }, "category2": { "0": { "mode": "email", "email": { "0": "who@cares.net" } } } } }

why resulting construction not same original documents? need rid of "_id" , "value" elements @ root , homecoming this:

{ "_id": objectid("542ec1a91d40cafd58b928b4"), "billing": { "category1": { "0": { "mode": "email", "email": { "0": "test@what.com" } } }, "category2": { "0": { "mode": "email" } } } }

how can done?

mongodb mapreduce

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -