[SERVER-40406] Add support for '$$NOW' and '$$CLUSTER_TIME' within the update command Created: 01/Apr/19  Updated: 29/Oct/23  Resolved: 17/May/19

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Write Ops
Affects Version/s: None
Fix Version/s: 4.1.12

Type: Improvement Priority: Major - P3
Reporter: Charlie Swanson Assignee: Bernard Gorman
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-40381 Add the ability to specify a pipeline... Closed
is depended on by SERVER-41115 Add $merge support for $$NOW and $$CL... Closed
is depended on by SERVER-40419 Remove feature flag guard of pipeline... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2019-05-20, Query 2019-06-03
Participants:

 Description   

This will likely involve accepting an additional argument to the update command, like we do for 'runtimeConstants' in aggregate. It will also involve propagating those constants from the update command on mongos or generating them on mongod in unsharded deployments.



 Comments   
Comment by Adrian B [ 06/Jul/21 ]

It seems that only the update with aggregation pipeline can use $$NOW.

Could it also be supported in the "classical" update (with update operators) ? 

I know $currentDate exists, but we cannot use it combined with another update operator ($setOnInsert, $push, ...) and sometime, using an update with aggregation pipeline would be unfavorable.

Example of use case : 

  • We want to do an upsert, with a field "creation-time", generated server-side.
  • The document contains an array where elements are added one by one (e.g. an array of events).
  • We want to watch, with a Change Stream, the changes on the array.

If we use an update with aggregation pipeline, each insertion of elements in the array with $concatArray will triggers an event containing all the content of the array. 
When the array can go up to several MB, this method quickly becomes a non-starter.

Note (if you are curious of my specific use case) : the "creation-time" is needed because we want to atomically (with only one operation) adds elements to an array in a "chunk" (or create one if chunk size is already at the limit), while allowing to retrieve the chunks in order. This would allow us to have an array of subdocuments (events) unrestricted to the 16 MB limit, while allowing to use a change stream to retrieve the events' data.

 

Comment by Githook User [ 17/May/19 ]

Author:

{'email': 'bernard.gorman@gmail.com', 'name': 'Bernard Gorman', 'username': 'gormanb'}

Message: SERVER-40406 Add support for $$NOW and $$CLUSTER_TIME in the update command
Branch: master
https://github.com/mongodb/mongo/commit/c7f86d2fce5ad0145b57007f83584cf96d02d9d4

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