Skip to content

Commit

Permalink
Merge pull request #9 from GhMartingit/fix_deleteone_bug
Browse files Browse the repository at this point in the history
Fix DeleteOne function bug
  • Loading branch information
GhMartingit authored Jun 6, 2023
2 parents b24afe1 + 815c600 commit f44aa91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package xk6_mongo
import (
"context"
"log"
"strings"
"errors"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down Expand Up @@ -39,6 +37,7 @@ func (*Mongo) NewClient(connURI string) interface{} {

return &Client{client: client}
}
const filter_is string = "filter is ";

func (c *Client) Insert(database string, collection string, doc map[string]string) error {
db := c.client.Database(database)
Expand Down Expand Up @@ -66,7 +65,7 @@ func (c *Client) InsertMany(database string, collection string, docs []any) erro
func (c *Client) Find(database string, collection string, filter interface{}) []bson.M{
db := c.client.Database(database)
col := db.Collection(collection)
log.Print("filter is ", filter)
log.Print(filter_is, filter)
cur, err := col.Find(context.TODO(), filter)
if err != nil {
log.Fatal(err)
Expand All @@ -83,7 +82,7 @@ func (c *Client) FindOne(database string, collection string, filter map[string]s
col := db.Collection(collection)
var result bson.M
opts := options.FindOne().SetSort(bson.D{{"_id", 1}})
log.Print("filter is ", filter)
log.Print(filter_is, filter)
err := col.FindOne(context.TODO(), filter, opts).Decode(&result)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -111,8 +110,8 @@ func (c *Client) DeleteOne(database string, collection string, filter map[string
db := c.client.Database(database)
col := db.Collection(collection)
opts := options.Delete().SetHint(bson.D{{"_id", 1}})
log.Print("filter is ", filter)
result, err := col.DeleteMany(context.TODO(), filter, opts)
log.Print(filter_is, filter)
result, err := col.DeleteOne(context.TODO(), filter, opts)
if err != nil {
log.Fatal(err)
}
Expand All @@ -124,7 +123,7 @@ func (c *Client) DeleteMany(database string, collection string, filter map[strin
db := c.client.Database(database)
col := db.Collection(collection)
opts := options.Delete().SetHint(bson.D{{"_id", 1}})
log.Print("filter is ", filter)
log.Print(filter_is, filter)
result, err := col.DeleteMany(context.TODO(), filter, opts)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion test-insertbatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default () => {
docobjs.push(getRecord());
}

client.insertBatch("test", "test", docobjs);
client.insertMany("test", "test", docobjs);
}

function getRecord() {
Expand Down

0 comments on commit f44aa91

Please sign in to comment.