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

$iset - set fields only on insert when upserting

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.1.3
    • Component/s: Querying
    • Labels:
      None

      It'd be nice if there was the ability to tell Mongo on an upsert, "set this field only if a new document is created".

      Example:

      db.users.update(

      { foo: 'bar'}

      , { $set:

      { baz: 'bap' }

      , $iset:

      { create_time: new Date() }

      }, true)

      You could also imagine an equivalent to only set fields when updating but not inserting, although when updating there are more things you might want to do than just set ($inc, $push, etc), this may need more thought as to best approach. Perhaps $updateonly which can then contain any number of possible modifications, e.g. { $updateonly: { $inc:

      { modifications: 1 }

      , $set:

      { modify_time: new Date() }

      }

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            ibwhite Ian White
            Votes:
            15 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: