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

Upsert prevents custom id from being used when insert is done instead of update

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.1
    • Component/s: Write Ops
    • Labels:
    • ALL

      The upsert command in mongo db is not allowing a custom id to be used when a new doc is inserted. For example, suppose a collection was created with all the docs having a custom id that is an auto-increment integer. Then, if an upsert is used, the developer is not able to specify an integer as the _id value to be inserted (if an insert is performed instead of an update).

      This is breaking the upsert capability on any collection which uses custom ids, since once upserts are used in such a collection, the _id value of any docs inserted as a result of an upsert will use the ObjectId, instead of the custom id as on all other docs in the collection.

      The fix would be to enable a $set command to be used in an upsert that specifies a value for _id, but the new _id value is only used if an insert is done instead of an update (since the _id value is immutable on existing docs).

      See: http://groups.google.com/group/mongodb-user/browse_thread/thread/40fcaa617ab99873

            Assignee:
            Unassigned Unassigned
            Reporter:
            mongodevuser Mongo User
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: