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

$merge not working without shard-key

    • Query Execution
    • Minor Change
    • ALL
    • Query 2020-11-30, Query 2020-12-14, Query 2020-12-28, Query 2021-01-11, Query 2021-01-25, Query Execution 2021-02-22, Query Execution 2021-03-08, Query Execution 2021-03-22, Query Execution 2021-04-05, Query Execution 2021-04-19, Query Execution 2021-05-03, Query Execution 2021-05-17, Query Execution 2021-05-31, Query Execution 2021-06-14, Query Execution 2021-06-28, Query Execution 2021-07-12, Query Execution 2021-07-26, QE 2021-08-09, QE 2023-08-21, QE 2023-09-04, QE 2023-09-18, QE 2023-10-02, QE 2023-10-16, QE 2023-10-30, QE 2024-07-22, QE 2024-08-05, QE 2024-08-19, QE 2024-09-02, QE 2024-09-16, QE 2024-09-30

      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:
            ivan.fefer@mongodb.com Ivan Fefer
            Reporter:
            wernfried.domscheit@sunrise.net Wernfried Domscheit
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: