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

FindOneAndUpdate returns no error when no document found according to the filter criteria

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • 1.0.1
    • BSON
    • None
    • Linux ubuntu 18.04 LTS

    Description

      I have this schema 

       

      {
        "name": "PCP"
        "age": 20
      }
      

      I am using `FindOneAndUpdate()` to find the document and update it.

      Its working fine for the cases in which there is a document present in the database as per the filter criteria. 

      For cases in which there exist not document in the database as per the filter criteria, it returns no errors. What is expected that if there exist not document as per the filter criteria, the function should return an error so that the end user know that the document he is trying to update does not exist. 

      I am using the following code 

       
       

      func (u *user) update(name string, age int) error {     
         collection := database.Collection(userCollection)     
         selector := bson.M{"name": name}     
         update := bson.M{"$set": bson.M{"age": age}}     
         ctx, cancelFunc := context.WithTimeout(context.Background(),        20*time.Second)     
         defer cancelFunc()     
         result := collection.FindOneAndUpdate(ctx, selector, update)     
         return result.Err() 
      }

       
       

      Attachments

        Activity

          People

            Unassigned Unassigned
            prakashpandey prakash
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: