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
0 answers

MongoDB controlled transaction abort

I worked with mongo driver for golang, but possibly that question is actual for other implementations. Do mongo driver always abort transaction in case errors? Can I prevent implicit abort for transactions? For example, for such code, I always get…
Ragnar
  • 141
  • 2
  • 15
0
votes
1 answer

MongoDB Go Driver unable to unmarshal nested documents correctly

I've a setter and getter that operates on a specific field in a collection. The setter works fine and the documents are updated as expected, however the getter does not return populated structs correctly. What am I doing wrong ? Collection as a Go…
sakshamsaxena
  • 107
  • 11
0
votes
1 answer

MongoDB distinct query and $in with Go

I'm having trouble with the distinct query in MongoDB. I can write it in Mongo shell, it works but I don't know how to implement it in Go code. Here is my Mongo shell code db.getCollection('company_role_function').distinct("rolecode", {rolecode : { …
ThanhLam112358
  • 878
  • 1
  • 20
  • 51
0
votes
1 answer

Getting queried elements from a object in Mongodb golang

The documents in collection look like this : { "id":"81f003b9-da3a-4480-9963-c9c8e01027af" "name": "name", "born": "birth date", "birthplace": "place" } I want to get only id and name elements from the document. My go…
RandomUser
  • 93
  • 1
  • 8
0
votes
0 answers

"server selection error:server selection timeout" Mongodb Go Driver

I want to connect to a remote Mongodb server. And in the process I get the error selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: :, Type: Unknown, State: Connected, Average RTT: 0, Last…
RandomUser
  • 93
  • 1
  • 8
0
votes
1 answer

Golang GraphQL MongoDB Struggling to get date and id out of the Database

I am new to Golang and Graphql so I probably messed a lot of the configuration up but I am struggling to get values returned from my database using the GraphQL API I created. Whenever I query my database using the GraphQL API I created in Golang It…
LucyEly
  • 63
  • 1
  • 13
0
votes
2 answers

mongodb getting 10_000 rows at a time

I'm trying to get 10000 document at a time in mongodb, but i got : Information : Driver https://github.com/mongodb/mongo-go-driver opt.SetBatchSize(15_000) opt.SetAllowPartialResults(false) index on timestamp Code : package main import ( …
0
votes
1 answer

How to add JSON unmarshalling to an external library type without embedding

I did a bit of searching for similar posts, but Go JSON unmarshalling is a hot topic and I couldn't see anything specifically for my question among all the other posts. Is there a way to add/register JSON unmarshalling logic for an existing type --…
crunk1
  • 2,560
  • 1
  • 26
  • 32
0
votes
1 answer

Insert document into mongodb with one field having dynamic structure

I'm trying to insert to MongoDB with Go where one field will have dynamic data. In my case, it will come from the other service through gRPC but I simplified example to this: package main import ( "context" "fmt" _struct…
Arūnas Smaliukas
  • 3,231
  • 6
  • 27
  • 46
0
votes
1 answer

BSON map to database models struct

Struggling to figure out the correct way to do this. Right now I can convert a bson map to my database model structs individually. But now I'm just repeating a lot of the same code. So is there a better way to do this? Example of code: type Agent…
Zeedinstein
  • 13
  • 1
  • 6
0
votes
1 answer

Passing in dynamic struct into function in golang

I having a couple of structs, Products and Categories. I have 2 functions listed below that have identical logic just different structs that are being used and returned. Is there anyway I can abstract out the struct data types and use the same…
Don Ellis
  • 71
  • 1
  • 8
0
votes
1 answer

Not able to install latest version of mongo-go-driver (v1.2.1)

I am not able to get v1.2.1 for mongo-go-driver. I am using dep to resolve dependency. My import block looks like- import ( "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/bson" …
0
votes
1 answer

Using DBRef in mongo go driver

I want to use DBref with go-mongo-driver but I couldn't find any example about it. How can I achieve this? I worked with Spring Data Mongodb before and you can indicate Dbref inside a class like : @DBRef private EmailAddress emailAddress; Is…
akinKaplanoglu
  • 728
  • 2
  • 8
  • 26
0
votes
1 answer

How to serialize nil pointer of structure with custom MarshalBSONValue into BSON?

mongodb official golang dirver used in my program. package main import ( "fmt" "github.com/pkg/errors" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/bsontype" "go.mongodb.org/mongo-driver/x/bsonx" …
Dr.Nemo
  • 1,451
  • 2
  • 11
  • 15
0
votes
1 answer

Why am I getting all zero value for certain field in my json from mongodb?

I'm fetching my data from MongoDB atlas in a Go web Server using the official mongodb-go-driver. I'm using json.Marshal to convert to json. but all values of certain fields becomes Zero. package main import…