Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28750

Add option to $currentDate to update field only if a update of other fields really occured

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      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.

        Attachments

          Activity

            People

            Assignee:
            mark.agarunov Mark Agarunov
            Reporter:
            hmducoulombier@marketing1by1.com Henri-Maxime Ducoulombier
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: