Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1818

BSON encoding, passing single string to $addToSet field

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • 1.4.4
    • BSON
    • None
    • Linux 4.14

    Description

      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?

      Attachments

        Activity

          People

            kevin.albertson@mongodb.com Kevin Albertson
            andrewhodel@gmail.com Andrew Hodel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: