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

Sharding edge case upserts documents with multiple _id attributes

    • Fully Compatible
    • ALL

      we have a large collection with a shard key on _id.c, example

      {_id : {"a":"foo","b":1234,"c":3456}

      . When performing upserts we found that passing a query of _id alone resulted in the query being broadcast. to address this waste of work (waste for all but 1 shard), we changed the query of the upsert to


      . this did properly route the upsert to the appropriate shard. it appears that with this configuration, if a document already exists based on _id, the update works fine. when the document needs to be created, mongodb mistakenly injects two _id attributes into the new document. we will see exactly what was provided in the query:


      This probably should not occur. a side effect is that any driver which parses this document will either take the first occurrence of the attribute or the last one. the PHP driver takes the last one, resulting in an incomplete _id value.

      The mongo shell does not output these documents correctly because of SERVER-718 (duplicate fields just repeat the first).


            scotthernandez Scott Hernandez (Inactive)
            wayne530 Y. Wayne Huang
            1 Vote for this issue
            6 Start watching this issue