Created
July 19, 2019 10:47
-
-
Save darkmavis1980/6391593263efeb11752c304a46d3080f to your computer and use it in GitHub Desktop.
mongo_aggregate_and_filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This will filter down to the matches with a specific player, with the matches being played after a specific date, | |
* and it will show only the aggregate matches after that date ignoring the previous ones | |
*/ | |
var dateFilter = new ISODate("2019-06-01T20:15:31Z"); | |
db.getCollection('competitions').aggregate([ | |
{ | |
$match: { | |
players: ObjectId("5c71c4c1185c610046f17911"), | |
'matches.date': { | |
$gte: dateFilter | |
} | |
} | |
}, | |
{ | |
$project: { | |
matches: { | |
$filter: { | |
input: '$matches', | |
as: 'item', | |
cond: { | |
$gte: ['$$item.date', dateFilter] | |
} | |
} | |
} | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment