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…
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 =…
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…
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…
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…
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…
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" :…
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 (
…
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
//…
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…
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…
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,…
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)…