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
0
votes
1 answer

Specifying a query in MongoDB using Go

Confused about how to translate the Javascript JSON commands back into something go will understand. Ok so here's the query in the mongo shell:: db.customers.find({acct_balance:{$gt:100000}}, {firstName: 1, surname:1, acct_balance:1,…
Deliri
  • 116
  • 1
  • 11
0
votes
1 answer

Marshalling pointers using mgo.Marshal()

I want to encode pointers differently than from values. Currently, if we have a struct: type Order struct { Item Tool AssociatedItem *Tool } both get inlined into a Order document inside mongo when marshalling. I need to be able…
Bernard
  • 16,149
  • 12
  • 63
  • 66
0
votes
0 answers

golang MongoDB aggregation: return empty objects for non-matches

I have the below mgo code to get objects matching an array of IDs pipeline := []bson.M{ bson.M{"$match": bson.M{"gsm_id": bson.M{"$in": fixtureIDs }}}, } But, I would like to return an array of the form below where missing fixtureIDs are…
user1387717
  • 1,039
  • 1
  • 13
  • 30
0
votes
1 answer

how to fetch the unknown mongo doc via mgo

Here is the piece of code that is trying to fetch all the docs from the mongodb. func fetchAll(db *mgo.Database) map[string]interface { var msg map[string]interface{} err := db.C("msg").Find(nil).All(&msg) if err != nil { …
Wilson Wang
  • 111
  • 5
0
votes
1 answer

Converting Method to generic way, finding with mgo

I'm trying to get getObj() function will be more general and could work with any type, not only User like in my code. I was thinking in return a interface instead a defined struct, but I can't fit this idea to my code, please could someone give me a…
Jzala
  • 43
  • 1
  • 7
0
votes
1 answer

Mgo pull update not working

I am trying to achieve the following functionality with mgo library from Go: db.artists.update( {_id: ObjectId("534944125117082b30000001")}, { $pull: { studies: { _id:…
eAbi
  • 3,220
  • 4
  • 25
  • 39
0
votes
1 answer

Parse a string without fixed set of keys for MongoDB find query

I have an API where the user will pass the query parameters they want to pass it to MongoDB. The API will take the string from the request parameter and pass it directly to Mongo find query. The query string won't have any fixed set of keys. It can…
jyotiska
  • 271
  • 2
  • 3
  • 8
0
votes
2 answers

How do I apply an update function to all the documents in a collection in MongoDB (using mgo)?

I've modeled a has-many relationship in MongoDB with a Group that has an array of Students as one of the fields. When a Student is deleted, I want to go through all the Groups, and for each Group that has the deleted_student in its Group.Students,…
ptwiggerl
  • 301
  • 4
  • 7
0
votes
1 answer

Importing Backup Collections with mGo

I have a BSON export from mongodump, and I also have a JSON export for mongoexport What would be the easiest way to import with mgo? Does mgo support inserting a backed-up BSON collection? Or do I need to use the JSON export, unmarshal it and then…
K2xL
  • 9,730
  • 18
  • 64
  • 101
0
votes
1 answer

Go/Mgo -> []byte in MongoDB, slice of unaddressable array

I'm getting a: reflect.Value.Slice: slice of unaddressable array Error when I'm trying to add a sha256 hash to a mongoDB with mgo. Other []bytes work fine. hash := sha256.Sum256(data) err := c.Col.Insert(bson.M{"id": hash}) Any idea what the…
Zap
  • 859
  • 1
  • 7
  • 10
0
votes
1 answer

Find out result of inserting object using mgo in Go

I would like to ask you if there is a way to find out if insertion was successful when inserting new object using collection. Insert(object) with single operation. What I mean is that, I don't want to send another query to the db to find out if…
Tek
  • 1,178
  • 1
  • 12
  • 22
0
votes
1 answer

How do I deal with an arbitrary hash returned from mongo in go (using mgo)?

All of the references I can find construct a struct to hold the return values, assuming that each returned record has the same schema. If they're really documents and don't have a consistent schema other than maybe a few queryable consistent…
fields
  • 4,433
  • 4
  • 27
  • 32
0
votes
1 answer

Golang / MGO -- panic: no reachable servers

I have the following function that connects to Mongo. For testing, I shutdown mongod, and want to allow the program to continue w/0 mongo if it's not available. It seems that MGO throws a panic if the server can't be connected, so I wrote a…
user2644113
  • 1,101
  • 3
  • 16
  • 24
0
votes
1 answer

Reset time.Time in mgo struct

Simplified struct: type User struct { ResetToken string `bson:"resettoken,omitempty" json:"resettoken"` ResetSent time.Time `bson:"resetsent,omitempty" json:"resetsent"` } Now on successful (password) reset it should set…
user2312578
0
votes
1 answer

Mgo-based app code structure dealing with connection pool and tcp timeouts

I'm curious how should I structure JSON REST API server in Go language with Mgo library. I have dozens of collections related with each other. I've created the gist with sample part of file structure in my current approach. It works great, but from…
Rafał Sobota
  • 1,468
  • 1
  • 17
  • 32