Core Server
  1. Core Server
  2. SERVER-1765

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

    Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major - P3 Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: planned but not scheduled
    • Component/s: Write Ops
    • Labels:
      None
    • Backport:
      No
    • # Replies:
      3
    • Last comment by Customer:
      true

      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

        Activity

        Hide
        Eliot Horowitz
        added a comment -

        We should make the syntax work for queries as well

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

        Any progress on this issue?

        Show
        Abdullah Battal
        added a comment - Any progress on this issue?
        Hide
        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
        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';

          People

          • Votes:
            15 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

            • Created:
              Updated:
              Days since reply:
              1 year, 1 week ago
              Date of 1st Reply: