如何查询从 mongodb mapReduce 生成的集合中的特定字段?
我应该输入什么来仅检索输出集合中的姓氏字段?
结果应该是:
{ "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}) } , 函数(key, value) { return null; }, {out: {reduce: 'output'}} )
{ "result" : "output", "timeMillis" : 6, "counts" : { "input" : 1, "发射”:1,“减少”:0,“输出”:1},“ok”:1,}
>db.output。find()
{ "_id" : ObjectId("50bc001a8e97247957c6000f"), "value" : { "firstname" : "John", "lastname" : "Doe" } }
>db.output.find( {}, {_id: 0})
{“价值”:{“名字”:“约翰”,“姓氏”:“Doe”}}