why insert duplicate document close the client?

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.0.1
    • Component/s: CRUD
    • None
    • Environment:
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      After I create an unique index for a field of a document, I insert a duplicate document into mongodb, when using mgo it reports duperr, but user this driver, it reports "client is disconnected" and it disconnects from server either.

       

      IMO, this error should not close the connection to the mongodb server, but just report/return an proper error.

       

       

      mongo.InitMongo()
      client := mongo.GetClient()
      c := client.Database("api-server").Collection("users")
      var user = bson.M{"name":"bob","age":12} //duplicate document
      r, err := c.InsertOne(nil, user)
      if err != nil {
         println(err.Error())  //reports client is disconnected
      }
      // test if really disconnected
      var result bson.M
       err=c.FindOne(nil, bson.M{"name":"bob"}).Decode(&result)
      if err != nil {
         glog.Errorln(err) // really disconnected
         return
      }
      
       println(result["age"])
      
      

       

            Assignee:
            Divjot Arora (Inactive)
            Reporter:
            daniel yang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: