Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-3672

Investigate changes in SERVER-51207: $merge not working without shard-key

    • Type: Icon: Investigation Investigation
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Tools and Replicator

      Original Downstream Change Summary

      $merge operation used to fail when encountering null or missing values in fields that merge is preformed on: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#std-label-merge-on

      Every $merge must be supported by a unique index.

      After this change we allow "on" fields to be null/missing if supporting index is NOT sparse.
      If supporting index is sparse, the error would be the same.

      We still don't allow arrays in "on" fields.

      One important difference is some customers may expect $merge to fail on null and handle this error in their code, but now this operation will just work.

      Description of Linked Ticket

      In Mongo 4.4, shard keys can be missing, see https://docs.mongodb.com/manual/core/sharding-shard-key/#shard-key-missing

      This works fine for insert of documents, however merge in aggregation-framework is failing:

      db = db.getSiblingDB("mip")
      db.createCollection("sharded_col")
      sh.enableSharding("mip")
      sh.shardCollection("mip.sharded_col", { tsi: 1 })
      
      db.sharded_col.insertOne({ a: 1 })
      
      db.sharded_col.aggregate([
         { $set: { a: 2 } },
         { $unset: "_id" },
         { $merge: { into: "sharded_col" } }
      ])
      
      { 
          "ok" : 0.0, 
          "errmsg" : "$merge write error: 'on' field 'tsi' cannot be missing, null, undefined or an array", 
          "code" : NumberInt(51132), 
          "codeName" : "Location51132", 
          "operationTime" : Timestamp(1601372348, 4), 
          "$clusterTime" : {
              "clusterTime" : Timestamp(1601372351, 40), 
              "signature" : {
                  "hash" : BinData(0, "wv5eJ/xcJoaS1m14aJeoSA3WSqo="), 
                  "keyId" : NumberLong(6854861305854033921)
              }
          }
      }
      
      

       

      If MongoDB permits missing shard key then it should also apply for merge. 

            Assignee:
            Unassigned Unassigned
            Reporter:
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: