Questions tagged [mongo-go]

Official MongoDB Go driver

Official driver page: https://docs.mongodb.com/ecosystem/drivers/go/

It is available here: https://github.com/mongodb/mongo-go-driver

Documentation (godoc): https://godoc.org/github.com/mongodb/mongo-go-driver

It was announced here: Considering the Community Effects of Introducing an Official MongoDB Go Driver

229 questions
0
votes
1 answer

Why can't I find the IDE-inserted data in terminal mode?

I was trying to insert data through Goland IDE in MongoDB. Though the connection is right and in the IDE output I got the ObjectID, I still cannot see the results from terminal directly. It seems that the database records a new document without any…
0
votes
1 answer

Mongo go driver transaction implementation with retries

Am trying to build transaction in mongodb with retries functionality as similar to other drivers like nodejs etc. This is my current implementation if session, err = client.StartSession(); err != nil { return err } if err =…
Muthu Rg
  • 632
  • 1
  • 6
  • 18
0
votes
1 answer

convert json parameters to bson for UpdateOne in mongo-go-driver

I am trying to use UpdateOne of mongo-go-driver library but this method take bson document. I give it a interface parameter (json). My question is to find best way to parse my json request to bson for updating fields dynamically. Thank you. func (s…
0
votes
1 answer

How to write nested bson.M{} correctly

Suppose we have the following struct: type shop struct { ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"` Brands *brand `json:"brand,omitempty" bson:"brand,omitempty"` } type brand struct { ID primitive.ObjectID…
moddos
  • 7
0
votes
1 answer

UpdateOne, ReplaceOne, FindOneAndReplace - patternmatch, but no upd data

I'm Using Mongo Go Adapter: github.com/mongodb/mongo-go-driver/ I'm trying different patterns but none of them working for me. //ref struct type userbase struct { Name string `bosn:"Name"` Coins int `bson:"Coins"` } //ref code, it's…
Dinamis
  • 1
  • 1
0
votes
1 answer

Mongodb-go-adapter FindOne spits out { } and { 0}

In general FindOne fmt.print result { }. I need to output Value. I'm using pretty much standard setup from documentation: https://docs.mongodb.com/ecosystem/drivers/go/ I have problems with creating query because most of examples are different; I've…
Dinamis
  • 1
  • 1
0
votes
1 answer

UpdateOne failed with E11000 duplicate key error

I'm trying to update document of MongoDB from go. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() c, _ := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017")) col :=…
mkiuchi
  • 3
  • 3
0
votes
1 answer

Creating a dynamic filter with mongo-go-driver

I want create a dynamic filter with the mongo-go-driver. For example, I have this…
SaroVin
  • 1,583
  • 3
  • 23
  • 46
0
votes
0 answers

How to read datetime in local timezone

I use github.com/mongodb/mongo-go-driver driver in golang My code struct: type Document struct { CreatedAt time.Time `bson:"createdAt"` } When I insert a document, it is inserted as ISODate (), it looks like this: { "createdAt" :…
erofeev
  • 101
  • 1
0
votes
1 answer

invalid request to read array when doing UnmarshalExtJSON

I'm trying to unmarshal extended JSON into a struct using UnmarshalExtJSON from go.mongodb.org/mongo-driver/bson It's giving me an error: invalid request to read array How can I unmarshal this data into my struct? MVCE: package main import ( …
user773737
0
votes
1 answer

How to turn DataBase access into a Function idiomatically in Go

I have built a Backend API in Go, it works however I want refactor the code for the DB access layer into a function - idiomatically. // Get the form data entered by client; FirstName, LastName, phone Number, // assign the person a unique i.d //…
0
votes
1 answer

Data Inconsistency with MongoDB using mongo-go-driver

FindOneAndReplace may or may not replace the document in MongoDB. The response indicates that the operation succeeded, but looking into MongoDB it was not updated at all. The MongoDB server version is MongoDB server version: 3.2.0 This bug is…
faraonc
  • 61
  • 1
  • 6
0
votes
1 answer

bulkwrite does not support multi-document transaction by using mongo-go-driver

I's using mongo-go-driver 0.0.18 to build a bulk write which is consisted of a "NewUpdateManyModel" and several "NewInsertOneModel". My mongo server is atlas M10 with replica sets. I built some goroutines to test if the transactions are atomic, the…
JJJ HHH
  • 21
  • 1
  • 3
0
votes
1 answer

How to set batchSize in change stream watch api (mongo-go-driver)?

I am passing batchSize using changestreamopt.BatchSize. But this not working this error occurred: BSON field '$changeStream.batchSize' is an unknown field Sample API call // coll is *mongo.Collection // ctx is context cur, err := coll.Watch(ctx,…
iammehrabalam
  • 1,285
  • 3
  • 14
  • 25
-1
votes
1 answer

How to store struct private fields in MongoDB?

I have a structure like this: type Document struct { ID primitive.ObjectID `bson:"_id,omitempty"` description string `bson:"description,omitempty"` } And I have the getter for description field: func (d *Document)…
Bookin
  • 282
  • 2
  • 16
1 2 3
15
16