646 questions
1
vote
1
answer
83
views
MongoDB Go Driver v2: How to Marshal a Nil Custom Type as BSON Null?
I’m using MongoDB GoLang Driver v2 and I want to store a custom money type in MongoDB.
If the value is nil, I want the BSON document to store price: null.
Example document I want:
{
"name":...
1
vote
0
answers
109
views
no reachable servers. MongoDB error with go using gopkg.in/mgo.v2
I am trying to establish connection with mongoDB using the below code
func getSession() \*mgo.Session {
// Connect to MongoDB on the default port
s, err := mgo.Dial("mongodb://localhost:...
2
votes
1
answer
205
views
Mongo-go driver version of session.copy()
I am migrating a go backend from using mgo to mongo-go. The service has lots of code and I have completed most of it except for a part that deals with session.Copy() method from the old mgo. The ...
2
votes
0
answers
182
views
Golang MGO driver with mongo atlas version 5 or above
Currently, most of my production is based on microservices, and the majority of the services have already been upgraded to the official MongoDB driver. However, with the end-of-life for version 4.X ...
1
vote
0
answers
62
views
golang mongodb sessionid format conversion
After linking to mongodb, the Sessionid needs to be converted back to the original format as a string
func main() {
uri := "mongodb://root:[email protected]:32082,172.22.50.25:32083,172.22.50....
3
votes
0
answers
39
views
How search with strength in mgo Golang
basically i have this query that searches from an array of names...now i want to make it case insensitive
in GO
err = c.Find(bson.M{
"name": bson.M{
"$in": ...
1
vote
0
answers
211
views
Connection from Go Application to MongoDB Is Not Persisting
I'm connecting a Go application to MongoDB using the following code:
session, sessionErr := mgo.Dial("127.0.0.1:27017")
The connection is established but doesn't persist as indicated in ...
2
votes
1
answer
2k
views
MongoDB error "no reachable servers" with golang
I just followed this tutorial on youtube(https://youtu.be/GwQ1hvuSNJA).
But I got an error "no reachable servers" after go run main.go
How can I figure it out? Should I change localhost to ...
0
votes
1
answer
685
views
MongoDb and Golang - $group and $match
I am trying to $match my data after $group but it does not work.
I have db with jobs.
Every job has {id, batchId(a few jobs can belong to one batch), createdAt, finishedAt}.
I cant understand why I am ...
3
votes
1
answer
1k
views
Avoid to save blank struct object in db
I am running the below code. When a user saved in db then blank address is saved I have assigned the null struct to address before save. I can not add the omitempty with all the fields for address ...
4
votes
0
answers
2k
views
Golang MongoDB query returns empty cursor?
I'm at a bit of an impasse here with a query that SHOULD by all accounts, return results. If I run the following query in mongosh:
db.events.aggregate([
{$unwind:"$features&...
-2
votes
1
answer
72
views
The most improved way to get all likes for each post in MGO?
Likes have different collection, so do Posts.
But, maybe it is more efficient and green that:
just getting all posts and when users hover on posts fetching likes
or when intersection api is triggered ...
3
votes
2
answers
533
views
How to store geo-spatial data in MongoDB with Go driver or mgo/qmgo?
I'm using MongoDB driver and mgo-forked qmgo in Go to operate MongoDB (version 5.x).
I have some geo-spatial data to store and query, and searched some articles and someone mentioned to create custom ...
1
vote
1
answer
1k
views
How to connect to mongoDB via ssl using .crt file in Go
I am trying to connect to a mongo database hosted in azure using the .crt file.
I am successfully able to connect from my linux machine terminal using command:
mongo mongodb://username:password@prod-...
0
votes
1
answer
451
views
How to return Mongodb Aggregate pipeline docs to ONE document?
I know this has got to be simple, but for the life of me I can't seem to generate the correct final stage in my pipeline to get this working. Here are the documents output from a stage that I have in ...