diff --git a/README.md b/README.md index d1ec7d53c8..29ef77b91f 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,10 @@ filter := bson.D{{"name", "pi"}} ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) defer cancel() err = collection.FindOne(ctx, filter).Decode(&result) -if err != nil { +if err == mongo.ErrNoDocuments { + // Do something when no record was found + fmt.Println("record does not exist") +} else { log.Fatal(err) } // Do something with result...