1,798
社区成员
发帖
与我相关
我的任务
分享
db.yourcollection.aggregate( { $match : {"username" : "bob" } } , { $unwind : "$friends" }, { $match : {"friends.age" : 18 } } )
var mFunction=function(){ filterFriends=[]; this.friends.forEach(function(s){ if(s.age==18){ filterFriends.push(s); } }); emit(this._id,{friends:filterFriends}); }
var rFunction=function(key,values){ return values[0];}
db.runCommand({mapReduce:'t1',map:mFunction,reduce:rFunction,out:{inline:1},query:{"friends.age":18}})