[SERVER-29193] Current date/time available in Aggregation pipeline Created: 15/May/17  Updated: 03/Apr/23  Resolved: 16/May/17

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.4.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Dennis Hoefakker Assignee: Kelsey Schubert
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-23656 Current timestamp variable for aggreg... Closed
Participants:

 Description   

It's very usefull to have the current (server) datetime available in the Aggregation Framework. Also with the 3.4 view functionality.

For example i have a very large collection of documents, containing a datetime field, i have created a view which returns this is a nice way.
BUT what i want to see are the entries of the last month.
When i add a find to the view, the match stage is added as the last stage, but for pipeline performance you want to limit the amount of documents in the first stage.
There is no way to use the current data/time in the aggregation pipeline.
When you can place the current datetime in the pipeline document you can do everything



 Comments   
Comment by Kelsey Schubert [ 16/May/17 ]

Hi HoefMeistert,

Thanks for the feature request. We're tracking this feature in SERVER-23656. Please feel free to vote for it and watch it for updates.

Thank you,
Thomas

Comment by Dennis Hoefakker [ 15/May/17 ]

The title states "Aggregation pipeline" but it would also be nice if your able to use it in a "normal" find command.

Something like : { date : { $gte : $currentDate.month(-1) }}

to get all documents machting date field greater and equal to now - 1 month

Comment by Dennis Hoefakker [ 15/May/17 ]

And the moment we can project a new ISODate to a field, that works, but a variable would also be nice (and documented )

{ $project : { current : new ISODate() }}

The problem i have with this "solution" is that i lost my index, because i first need to project

My question of inserting in a document is wrong, you want to use it in the first match stage (currentDate.month(-1) or something similar)

Generated at Thu Feb 08 04:20:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.