[SERVER-28750] Add option to $currentDate to update field only if a update of other fields really occured Created: 12/Apr/17  Updated: 26/Apr/19  Resolved: 18/Apr/17

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

Type: Improvement Priority: Minor - P4
Reporter: Henri-Maxime Ducoulombier Assignee: Mark Agarunov
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Hello,

I don't know if it's possible because I don't know the mechanics inside the update process well enough, but I thought this would be interesting to extend the $currentDate operator to update the date if and only if (optionnaly) at least 1 other fields in document was updated.

As an example, imagine I have a document :

{"_id": 1, "firstname":"Henri", "du":ISODate("2017-04-12T19:10:28.000Z")}

And this update request :

db.test.update({"firstname": "Henri"},
	{
	 	"$set":{"firstname": "Henri"},
		"$currentDate":{"du": true} 
	 	
	},
	{
		"upsert": true
	}
);

Appart from the $currentDate, this update does not actually update anything in the document. And I thought this would be useful to have $currentDate update the "du" fields only if firstname had changed.

Maybe there is a design pattern to do that another way, but in my application, I have to do a lot of bulk updates and sometimes, with data that has already been written and thus, updates doing nothing...

Thanks for any input on the matter.



 Comments   
Comment by Ian Whalen (Inactive) [ 26/Apr/19 ]

Switching "Drivers Changes Needed" from "Maybe" to "Not Needed" since this was closed as something other than Fixed.

Comment by Mark Agarunov [ 18/Apr/17 ]

Hello hmducoulombier@marketing1by1.com,

Thank you for the report. Looking over the behavior you're describing, this appears to be the same behavior requested in SERVER-13578. I have closed this ticket as a duplicate, so please follow SERVER-13578 for updates on this issue.

Thanks,
Mark

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