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…
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…
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 : {
…
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…
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…
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…
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 (
…
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 --…
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…
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…
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…
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"
…
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…
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"
…
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…