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...
Socio asked 28/3, 2019 at 13:25

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...
Woebegone asked 26/6, 2019 at 12:7

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...
Solicit asked 12/5, 2020 at 3:48

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"...
Foreordain asked 26/3, 2020 at 10:9

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...
Suffrage asked 14/9, 2020 at 7:34

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:...
Montherlant asked 22/8, 2020 at 10:32

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...
Altissimo asked 10/1, 2019 at 17:12

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...
Jun asked 2/1, 2020 at 10:9

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...
Teethe asked 25/2, 2019 at 23:21

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...
Carlycarlye asked 18/9, 2019 at 17:56

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...
Stancil asked 21/8, 2019 at 7:31

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...
Kiley asked 4/12, 2018 at 20:37

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...
Takamatsu asked 1/11, 2018 at 22:3

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...
Thirddegree asked 27/10, 2018 at 8:5

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...
Mccauley asked 20/4, 2018 at 3:0

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...
New asked 4/4, 2018 at 17:52
1

© 2022 - 2025 — McMap. All rights reserved.