How do I query for specific fields in a collection produced from mongodb mapReduce?
What should I enter to retrieve only the lastname field in the output collection?
The result should be:
{ "lastname" : "Doe" }
> version()
version: 2.2.2
> db.test.save( { first: "John", last: "Doe" } )
>db.test.find()
{ "_id" : ObjectId("50bc001a8e97247957c6000f"), "first" : "John", "last" : "Doe" }
> db.test.mapReduce(
function() { emit( this._id, {firstname:this.first, lastname:this.last} ) } , function(key, value) { return null; }, {out: {reduce: 'output'}} )
{ "result" : "output", "timeMillis" : 6, "counts" : { "input" : 1, "emit" : 1, "reduce" : 0, "output" : 1 }, "ok" : 1, }
>db.output.find()
{ "_id" : ObjectId("50bc001a8e97247957c6000f"), "value" : { "firstname" : "John", "lastname" : "Doe" } }
>db.output.find( {}, {_id:0} )
{ "value" : { "firstname" : "John", "lastname" : "Doe" } }