[SERVER-28144] Allow $currentDate in queries Created: 28/Feb/17 Updated: 06/Dec/22 Resolved: 19/May/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 3.4.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Alan Hengle [X] | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Assigned Teams: |
Query
|
||||||||
| Participants: | |||||||||
| Description |
|
There seems to be no way to retrieve the system date of the mongodb server. This is a problem if the client time is not synched with the server (which it will usually not be). Currently the only option is to use a new Date() from either javascript on the client or the language of the driver, or possibly using a $where. This could easily be solved by allowing $currentDate to be used in queries rather than just in updates. The problem with not having this is, for example, on a findAndModify when a Date or Timestamp value is part of the query. It would be best to have the corresponding date field be from a uniform base, such as what $currentDate is, namely the system time of the server. Consider when querying against an expiration time, it is somewhat useless from multiple servers, with only gross time intervals making sense. |
| Comments |
| Comment by David Storch [ 19/May/17 ] |
|
Hi cjRay, We've noticed that this appears to be a duplicate of Best, |
| Comment by Andy Schwerin [ 28/Feb/17 ] |
|
This raises some questions for replica sets and sharded clusters, where the clocks are not necessarily well synchronized. Even in systems running ntp, there can be a >1 ms clock drift. I'm not saying that we should rule out this feature request, but that is why we've shied away from expanding the use of $currentDate in the past. |
| Comment by Alan Hengle [X] [ 28/Feb/17 ] |
|
Actually I would add one other request, and that is to enhance the functionality of $currentDate to allow for functions on the date, for example $currentDate: {expiration: {$add: {hour: 1}}}. |