-
Type: Bug
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: 3.4.9
-
Component/s: Aggregation Framework
-
None
-
ALL
To get the last documents based on their datetime property we can use:
db.lightningsStrikes.find({ datetime: { $gte: new Date(new Date() - 1000*60*20) } })
The command above gets lightning strikes of last twenty minutes.
To create a view of it we should to be able to do this: right?
db.createView("lastLightningStrikes", "lightningStrikes", [{ $match: { datetime: { $gte: new Date(new Date() - 1000*60*20) } } }])
But createView is interpreting new Date() at creation time instead of querying time, as below:
db.system.views.find().pretty()
{ "_id" : "lightning.latestLightningStrikes", "viewOn" : "lightningStrikes", "pipeline" : [ { "$match" : { "datetime" : { "$gte" : ISODate("2017-09-28T19:25:34.410Z") } } } ] }
I suppose that it should be as below:
{ "_id" : "lightning.latestLightningStrikes", "viewOn" : "lightningStrikes", "pipeline" : [ { "$match" : { "datetime" : { "$gte" : new Date(new Date() - 1000*60*20) } } } ] }
- duplicates
-
SERVER-23656 Current timestamp variable for aggregate expressions
- Closed