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

self referential updates? WAS: allow access to old row value during update

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: planned but not scheduled
    • Component/s: Write Ops
    • Labels:
      None

      Description

      Right now, you can't access the old value of a row during an update. You have to decide what each field you want to update should look like on the client side. So you can't do:
      { $set : { "creation_timestamp" : coalesce(old.creation_timestamp, <now>) }}
      or:
      { $set : { "priority" : max(old.priority, 3) }}
      or:
      { $set : { "widgets_being_processed" : old.widgets_needing_processing }}

      ... or any equivalent.

      You can do this kind of thing with two queries, but that has potential performance and concurrency problems.

      From what I know of the Mongo architecture I don't see why access to this information should be impossible. I don't know what the syntax would be, of course.

      See also my original email question: http://groups.google.com/group/mongodb-user/browse_thread/thread/1c7b424cf9ef48e8/877621f662ca4cc0

        Issue Links

          Activity

          Hide
          eliot Eliot Horowitz added a comment -

          We should make the syntax work for queries as well

          Show
          eliot Eliot Horowitz added a comment - We should make the syntax work for queries as well
          Hide
          battal84 Abdullah Battal added a comment -

          Any progress on this issue?

          Show
          battal84 Abdullah Battal added a comment - Any progress on this issue?
          Hide
          justanyone Kevin J. Rice added a comment - - edited

          We're looking for this, too. In our document:

          doc =

          { ... 'keyname' : 'ABCDE' ... }

          We'd like to do the following as in-place modifications to strings:

          • append a string to an existing string ($append: {'keyname' : 'FG'}

            ) resulting in 'ABCDEFG';

          • prepend a string to an existing string ($prepend: {'keyname' : 'FG'}

            ) resulting in 'FGABCDE';

          • remove characters from the front of a string ($lcut : {'keyname' : 2 }

            ) resulting in 'CDE';

          • remove characters from the end of a string ($rcut : {'keyname' : 2 }

            ) resulting in 'ABC';

          • trim whitespace from left, right or both sides;
          • change a string into a substring (start, length) of itself;
          • remove characters before or after a substring;
          • regex substitutions (Perl-like) on a string. For instance:

            { $regexSub:{'field':'keyname','searchRegex':'(.*)CD(.*)','replRegex':'\1__new__\2','flags':'gi'}} 

            resulting in 'AB_new_E';

          Show
          justanyone Kevin J. Rice added a comment - - edited We're looking for this, too. In our document: doc = { ... 'keyname' : 'ABCDE' ... } We'd like to do the following as in-place modifications to strings: append a string to an existing string ($append: {'keyname' : 'FG'} ) resulting in 'ABCDEFG'; prepend a string to an existing string ($prepend: {'keyname' : 'FG'} ) resulting in 'FGABCDE'; remove characters from the front of a string ($lcut : {'keyname' : 2 } ) resulting in 'CDE'; remove characters from the end of a string ($rcut : {'keyname' : 2 } ) resulting in 'ABC'; trim whitespace from left, right or both sides; change a string into a substring (start, length) of itself; remove characters before or after a substring; regex substitutions (Perl-like) on a string. For instance: { $regexSub:{'field':'keyname','searchRegex':'(.*)CD(.*)','replRegex':'\1__new__\2','flags':'gi'}} resulting in 'AB_ new _E';
          Hide
          yashiikagupta Yashika Ketan Gupta added a comment -

          Whats the progress? Can we use/append/prepend a string to old value of field while updating that field??

          Show
          yashiikagupta Yashika Ketan Gupta added a comment - Whats the progress? Can we use/append/prepend a string to old value of field while updating that field??
          Hide
          davparker David Parker added a comment -

          I'm looking for this capability as well. Seems like it should be a fundamental feature with update.
          Looking forward to when the solution is implemented.

          Show
          davparker David Parker added a comment - I'm looking for this capability as well. Seems like it should be a fundamental feature with update. Looking forward to when the solution is implemented.
          Hide
          3lricko Ricardo Gonzalez added a comment -

          This issue was created on 2010 Is there any possibility that this issue could be addressed this year?
          Any reference you could provide about what is the best practice for this? I'm learning mongodb and it's kind of shocking not to have this functionality. Tks in advance!

          Show
          3lricko Ricardo Gonzalez added a comment - This issue was created on 2010 Is there any possibility that this issue could be addressed this year? Any reference you could provide about what is the best practice for this? I'm learning mongodb and it's kind of shocking not to have this functionality. Tks in advance!

            People

            • Votes:
              25 Vote for this issue
              Watchers:
              21 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since reply:
                2 weeks, 3 days ago
                Date of 1st Reply: