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

$merge not working with partial index

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 4.4.8
    • None
    • None
    • ALL
    • Hide

       

      db.source.insertOne(
         { id: 1, foo: 999 }
      )
       
      db.target.insertMany([
         { id: 1, foo: 123, merge: 0 },
         { id: 2, foo: 456, merge: 0 },
         { id: 1, foo: 789 }
      ])
       
      db.runCommand(
         {
            createIndexes: "target",
            indexes: [{
               name: "key",
               key: { id: 1 },
               unique: true,
               partialFilterExpression: { merge: { $exists: true } }
            }]
         }
      )
       
      db.source.aggregate([
         { $addFields: { merge: 1 } },
         {
            $merge: {
               into: "target",
               on: "a"
            }
         }
      ])
       
      Error: command failed: {
      	"ok" : 0,
      	"errmsg" : "Cannot find index to verify that join fields will be unique",
      	"code" : 51183,
      	"codeName" : "Location51183"
      } : aggregate failed :
      
      

       

       

      Show
        db.source.insertOne( { id: 1 , foo: 999 } )   db.target.insertMany([ { id: 1 , foo: 123 , merge: 0 }, { id: 2 , foo: 456 , merge: 0 }, { id: 1 , foo: 789 } ])   db.runCommand( { createIndexes: "target" , indexes: [{ name: "key" , key: { id: 1 }, unique: true , partialFilterExpression: { merge: { $exists: true } } }] } )   db.source.aggregate([ { $addFields: { merge: 1 } }, { $merge: { into: "target" , on: "a" } } ])   Error: command failed: { "ok" : 0 , "errmsg" : "Cannot find index to verify that join fields will be unique" , "code" : 51183 , "codeName" : "Location51183" } : aggregate failed :    

    Description

      I have two collections where I like to run an aggregation pipeline with $merge. However, the target collection has a partial unique index. According documentation $merge also works with spare indexes, so I would assume a partial index should also work.

      Attachments

        Issue Links

          Activity

            People

              edwin.zhou@mongodb.com Edwin Zhou
              wernfried.domscheit@sunrise.net Wernfried Domscheit
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: