BSON encoding, passing single string to $addToSet field

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.4.4
    • Component/s: BSON
    • None
    • Environment:
      Linux 4.14
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      This fails:

       

      update := bson.D{
      
                                       {"$set", f},
      
                                       {"$addToSet", bson.E{"outsideIp", "string"}},
      
      }
      
       
      
      updateResult, err := collection.UpdateOne(context.TODO(), filter, update)
      
      

       

      This works:

       

      update := bson.D{
      
                                       {"$set", f},
      
      }
      
       
      
      updateResult, err := collection.UpdateOne(context.TODO(), filter, update)
      
      

       

       

      Here is the error message:

       

      multiple write errors: [\{write errors: [{Cannot apply $addToSet to non-array field. Field named 'key' has non-array type string}]}, \{<nil>}]
      
      

       

      I only want to use $addToSet with a single string, as documented in the mongodb docs:

       

      db.inventory.update( { _id: 1 }, { $addToSet: { tags: "accessories" } } )
      
      

       

      What's going on here?

            Assignee:
            Kevin Albertson
            Reporter:
            Andrew Hodel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: