mongodb - Mongo Aggregation $filter on ISO date value -
i have following document
{ "_id": "57b4c5f0291ebb13110b888e", "first": "john", "last": "smith", "email": "john.smith@gmail.com", "fulfillments": [ { "_id": "57b683e531a5a21679b78e6d", "created_by_name": "john smith", "created_by_id": "57b4c5f0291ebb23110b888e", "fulfilled_by_name": "john smith", "fulfilled_by_id": "57b4c5f0291ebb13110b888e", "date": new date("2016-08-23t13:58:15-0700") } ] }
for have mongo query want return list of fulfillments have not occured. means date
property on fulfillment embedded document greater current time.
db.users.aggregate([ { $match : { "_id" : "57b4c5f0291ebb13110b888e" } }, { $project : { "fulfillments" : { $filter : { "input" : "$fulfillments", "as" : "item", "cond" : ...something here filter on 'date' } } } }, { $unwind : "$fulfillments" }, { $project : { "created_by_name" : "$fulfillments.created_by_name", "created_by_id" : "$fulfillments.created_by_id", "fulfilled_by_name" : "$fulfillments.fulfilled_by_name", "fulfilled_by_id" : "$fulfillments.fulfilled_by_id", "date" : "$fulfillments.date" } } ])
i can't figure out proper way filter on fulfillments date
has not occured.
the following should give desired result
... $project : { "fulfillments" : { $filter : { "input" : "$fulfillments", "as" : "item", "cond" : { $gt: [ "$$item.date", new date() ] } } } } ...
Comments
Post a Comment