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

BSON encoding, passing single string to $addToSet field

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

      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@mongodb.com Kevin Albertson
            Reporter:
            andrewhodel@gmail.com Andrew Hodel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: