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

$iset - set fields only on insert when upserting

    Details

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

      Description

      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() }

      }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: