Created
March 20, 2018 14:04
-
-
Save silgon/9d202c4046ba9a6d301c05e16a44b98b to your computer and use it in GitHub Desktop.
mongo aggregation unwind example
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
| db.t4.insert({ | |
| "_id" : ObjectId("512e28984815cbfcb21646a7"), | |
| "list" : [ | |
| { | |
| "a" : ISODate("2012-12-19T06:01:17.171Z"), | |
| "b" : 5 | |
| }, | |
| { | |
| "a" : ISODate("2013-12-19T06:01:17.171Z"), | |
| "b" : 5 | |
| }, | |
| { | |
| "a" : ISODate("2014-12-19T06:01:17.171Z"), | |
| "b" : 5 | |
| }, | |
| { | |
| "a" : ISODate("2015-12-19T06:01:17.171Z"), | |
| "b" : 10 | |
| }, | |
| { | |
| "a" : ISODate("2016-12-19T06:01:17.171Z"), | |
| "b" : 5 | |
| } | |
| ] | |
| }) | |
| db.t4.aggregate( | |
| { $match: {_id: ObjectId("512e28984815cbfcb21646a7")}}, | |
| { $unwind: '$list'}, | |
| { $match: {'list.a': {$gt: ISODate("2013-12-19T06:01:17.171Z")}}}, | |
| { $group: {_id: '$_id', list: {$push: {"val":'$list.a',"b":"$list.b"}}}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment