Questions tagged [mgo]

mgo (pronounced as mango) is a MongoDB driver for the Go language that implements a rich and well tested selection of features under a very simple API following standard Go idioms.

mgo (pronounced as mango) is a driver for the language that implements a rich and well tested selection of features under a very simple API following standard Go idioms.

Note that the "original" mgo driver (github.com/go-mgo/mgo) developed by Gustavo Niemeyer has gone dark (unmaintained). Even the author himself recommends to use the community supported fork github.com/globalsign/mgo which is in much better shape.

Links

644 questions
9
votes
1 answer

Why can't I find the ID using the mgo library of golang?

I am using mgo library for mongo operationg in golang and here is my code : session.SetMode(mgo.Monotonic, true) coll := session.DB("aaaw_web").C("cron_emails") var result Result fmt.Printf("%v", message.ID) err =…
Gaurav Garg
  • 137
  • 1
  • 9
9
votes
2 answers

mgo convert bson.objectId to string(hex) in html template

I know this problem maybe duplicate to this one. But it hasn't get a satisfied answer till now. And I really want to draw some attention to get a solution as soon as possible. So I beg you not to close this issue unless you have the solution and…
armnotstrong
  • 8,605
  • 16
  • 65
  • 130
9
votes
2 answers

how to get distinct values in mongodb using golang

I tried to retrieve a document from my collection with unique id. I have a collection with fields: name, age, city, and rank. I want to get 'city' results from mongodb using golang. My struct code type exp struct { name string `bson:"name"` …
manigandand
  • 2,094
  • 2
  • 15
  • 21
8
votes
1 answer

MongoDB in Go with mgo, operators with bson.M / bson.D always got syntax error

It is kind of stupid syntax error, tried tons of ways, just couldn't get it work, someone please help. MongoDB in Go with mgo, I just tried to simplify use the $ne operator, code like below, but kept getting compile syntax error: line 15: convIter…
lnshi
  • 85
  • 1
  • 1
  • 5
8
votes
2 answers

Concurrency in gopkg.in/mgo.v2 (Mongo, Go)

I wish to use MongoDB in webapp written in Go. Can I have one mgo.Session and use it concurrently in web app. e.g. in http.Handler or should I call Session.Copy and Session.Close -> make pool of sessions. It sounds contradictory somewhere I read…
Max
  • 6,286
  • 5
  • 44
  • 86
8
votes
1 answer

How do I create a text index in mongodb with golang and the mgo library?

I'm trying to do a full text search on a collection, but in order to do that I need to create a text index (http://docs.mongodb.org/manual/tutorial/create-text-index-on-multiple-fields/) The mgo library provides an EnsureIndex() function however,…
Ryan Epp
  • 931
  • 1
  • 10
  • 21
7
votes
1 answer

How can I ignore duplicate key error & proceed insertion, While insert many documents with MongoDB-mgo?

When I insert multiple documents with insert(docs...), Operation is failing & fails to insert documents if one duplicate key in a document exists in list of documents. How can I ignore this error, So all documents but not the duplicates can be…
zxxhonest
  • 73
  • 1
  • 3
7
votes
1 answer

MongoDB connection fails on multiple app servers

We have mongodb with mgo driver for golang. There are two app servers connecting to mongodb running besides apps (golang binaries). Mongodb runs as a replica set and each server connects two primary or secondary depending on replica's current state.…
RuslanN
  • 398
  • 3
  • 18
7
votes
2 answers

MongoDB admin commands with mgo driver

Is it possible, given admin creds, to run mongo shell commands such as db.stats(), rs.status() and db.serverStatus() external to the mongo shell via the official Go driver for MongoDB (mgo)?
kylemclaren
  • 768
  • 6
  • 14
7
votes
1 answer

how to do a like query using mgo package for golang

I am trying to do a like query using mgo with no luck. what I want is a mongodb query similar to db.organisation.find( { "permalink" : /org.*/ } ) I am still stuck at sess.DB(db).C(cApp). Find(bson.M{"permalink": "org:bms.*"}). All(&m)
Sumit M Asok
  • 2,950
  • 7
  • 29
  • 38
7
votes
1 answer

Connections pool in Go mgo package

In the article running-mongodb-queries-concurrently-with-go said that mgo.DialWithInfo : Create a session which maintains a pool of socket connections to MongoDB, but when I looking for in the documentacion of the function DialWithInfo I…
Carlos Andrés García
  • 1,483
  • 2
  • 15
  • 30
6
votes
1 answer

How can I convert my mgo sessions to mongo-go-driver clients using connection pooling?

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 NewMonotonicConnection() (conn *Connection, success bool) { …
TopherGopher
  • 655
  • 11
  • 21
6
votes
1 answer

How can I know if a mgo session is closed

I'm using *mgo.Session of MongoDB driver labix_mgo for Go, however I don't know if a session is closed. When I use a closed session, a runtime error will be raised. I want to skip the session copy if I know a session is closed.
xjpsjtu
  • 73
  • 7
6
votes
1 answer

Partial update of embedded document in mongoDB using mgo

I have the following model: type UserModel struct { Id string `bson:"_id,omitempty"` CreatedAt *time.Time `bson:"createdAt,omitempty"` BasicInfo *UserBasicInfoModel `bson:"basicInfo,omitempty"` } //…
TheoK
  • 3,601
  • 5
  • 27
  • 37
6
votes
1 answer

How to add Clone and Copy functions in mocking MongoDB in Go?

I read this article and it has good guides for mocking MongoDB in Go. But there are some problems in Clone() and Copy() methods. I create this interfaces and structs: type ISession interface { DB(name string) IDatabase Close() Clone()…
Vahid Jafari
  • 916
  • 6
  • 21
1 2
3
42 43