Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

wind in mongoose

//Use Group on _id with $push operator to return all players into an array.

Team.aggregate()
        .match({'_id' : new ObjectId(teamId)})
        .unwind('players')
        .unwind('players.trikots')
        .match({'players.trikots.color' : 'red', 'players.trikots.isNew' : true})
        .group({'_id':'$_id','players': {'$push': '$players'}})
        .exec(sendBack);

// if you want any other field to be included in the final doucment
// add it to _id field during group operation.

.group({'_id':{'_id':'$_id','some_other_field':'$some_other_field'},'players': {'$push': '$players'}})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #wind #mongoose
ADD COMMENT
Topic
Name
6+8 =