mongo-go Questions
2
Solved
I can't get the official go mongo driver to successfully return objects that are queried via a regex query.
I already know how to do it via the mongo shell and get my expected results.
With this e...
3
I'm fetching a document from MongoDB and passing it into function transform, e.g.
var doc map[string]interface{}
err := collection.FindOne(context.TODO(), filter).Decode(&doc)
result := tran...
4
I would like to get ObjectID as a string because I have other storage types, so I want to avoid to use primitive.ObjectID in my struct to keep the layers independent.
I'm new to Golang, thanks.
pa...
4
Solved
I am trying to convert type primitive.ObjectID to string type in Go. I am using mongo-driver from go.mongodb.org/mongo-driver.
I tried using type assertion like-
mongoId := mongoDoc["_id"...
3
Solved
When I insert into a collection with the new MongoDB Go driver I get a duplicate exception that I can see when spewing it. (mongo.WriteException) multiple write errors:
[{write errors: [{E11000 ...
Hindu asked 6/7, 2019 at 19:14
2
Solved
This specifc question is in relation to using mongodb with the golang package mongo-driver, but I would assume this applies across most interfaces with mongodb.
When using Find to query some data f...
Lemus asked 9/10, 2020 at 14:6
1
Solved
I am using mongo-driver from go.mongodb.org/mongo-driver. I already converted primitive.ObjectID to string
Using this link Primitive.ObjectID to string
Now i need to convert string to primitive.Obj...
0
I have this one-to-many reference relationship in graphql with Mongo go driver.
type User {
id: ObjectID!
email: String!
username: String!
posts: [Post!]!
}
type Post {
id: ObjectID!
author:...
2
Solved
I was trying to decode the data of the cursor into a map[string]interface{}, I tried it directly but it doesn't works at all, so I fount that I have to convert it to a BSON document and next conver...
3
Solved
I'm a beginner in both go and mongodb.
I try to decode a DocumentResult into a struct using bson tags, and it does not work for a custom type wrapping a string.
Can it be done without changing the ...
Scrivenor asked 26/8, 2018 at 8:30
3
Solved
I would like to know if there's any approach that would allow me to ignore null types while unmarshalling a MongoDB document into a Go struct.
Right now I have some auto-generate Go structs, somet...
Amery asked 21/11, 2019 at 22:2
2
Solved
I am watching a tutorial on how to create Go restful APIs that use MongoDB for persistence (this one to be more precise).
The instructor is using in his model (struct) both json and bson tags, som...
2
Solved
I checked out the answer here but this uses the old and unmaintained mgo. How can I find all documents in a collection using the mongo-go-driver?
I tried passing a nil filter, but this does not re...
1
Solved
Long, long ago, when we were using mgo.v2, we created some wrapper functions that copied the session, set the read pref and returned that for consumption by other libraries, e.g.
func NewMonotonic...
1
Solved
I need to do addToSet operation using official Go MongoDB driver.
In MongoDB we have some docs:
{ _id: 2, item: "cable", tags: [ "electronics", "supplies" ] }
Then to perform addToSet:
db.inve...
1
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 gor...
1
Solved
I'm working with https://github.com/mongodb/mongo-go-driver and
currently trying to implement a partial update of such struct
type NoteUpdate struct {
ID string `json:"id,omitempty" bson:"_id,omi...
1
Solved
How can I filter fields with the mongo-go-driver.
Tried it with findopt.Projection but no success.
type fields struct {
_id int16
}
s := bson.NewDocument()
filter := bson.NewDocument(bson.EC.O...
Hickson asked 2/11, 2018 at 14:8
1
Solved
I'm migrating from mgo driver, and my function looks like this:
queue := collection.Bulk()
for j := range changes {
..
queue.Update(doc, update)
}
saveResult, err := queue.Run()
This makes som...
1
Solved
After using InsertOne to create a new document, when I return the result I'm getting an array of numbers rather than an ObjectID. In the DB, the id is generating fine.
type User struct {
ID stri...
2
Solved
I'm inserting new item in collection. Using official mongo go driver for this (https://github.com/mongodb/mongo-go-driver).
collection.InsertOne(context.Background(), map[string]interface{}{
"str...
1
© 2022 - 2025 — McMap. All rights reserved.