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

Query with an array as parameter, how to convert to GoLang mgo?

I have the following query: db.getCollection('spawnlocations').find({ 'location': { '$geoWithin': { '$center': [[-73.94075, 40.789138], 5000] } }, "expirationtimems": { "$gte": 1234567890 }, "_id": {…
Valerio Santinelli
  • 1,592
  • 2
  • 27
  • 45
0
votes
1 answer

Revel with mgo.v2 - How to return all data from a collection as json?

I'm trying to build an API endpoint using Revel for Go. My models/models.go looks like this - type Category struct { Name string `bson:"name"` Slug string `bson:"slug"`} func GetCategories(s *mgo.Session) *Category { var results…
Gaurav Ojha
  • 1,147
  • 1
  • 15
  • 37
0
votes
1 answer

How to defer an mgo Session until it's fully streamed to the client?

I want to close an mgo session after it' fully streamed to the client. At first, I thought this might work, but it seems the defer just waits until the the func begins to return or something. func (c App) OpenFile(fileId string) revel.Result { …
pward
  • 1,049
  • 1
  • 8
  • 17
0
votes
2 answers

Are these the same versions/distributions of mgo?

I have found two places of the mongodb driver in Go http://godoc.org/gopkg.in/mgo.v2 and http://godoc.org/gopkg.in/mgo.v2/bson http://godoc.org/labix.org/v2/mgo and http://godoc.org/labix.org/v2/mgo/bson Are they the same distribution and version…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
1 answer

Matching structure to mgo result

I have the following document in my local mongodb: _id 25dd9d29-efd5-4b4e-8af0-360c49fdba31 name Reykjavik initialDiseaseColouring blue In my code I set up a city structure as the following: type City struct { ID bson.ObjectId…
AlwaysNull
  • 348
  • 2
  • 4
  • 15
0
votes
2 answers

how to build dynamic structure in golang?

I have this json file,In this json file there are n number of key as we…
Chetan Kumar
  • 328
  • 1
  • 4
  • 18
0
votes
1 answer

How to use $unwind in golang?

I want the result in go as the mongo shell provide me. In mongo shell the data is like this: db.user.aggregate([{$unwind:"$user"}]).pretty() { "_id" : ObjectId("57307906f051147d5317984e"), "user" : { "firstName" : "chetan", …
Chetan Kumar
  • 328
  • 1
  • 4
  • 18
0
votes
1 answer

Not understanding how mongoDB Update works in Go

I'm trying to implement a MongoDB update for a Go struct. Stripped down to essentials, it looks something like this: type MyStruct struct { Id bson.ObjectId `bson:"_id"` Fruit string `bson:"fruit"` } func TestUpdate(t…
Scott Deerwester
  • 3,503
  • 4
  • 33
  • 56
0
votes
1 answer

select function does't work to only get the array i want

i have a document like this { "_id": { "$oid": "570bc73da8ebd9005dd54de3" }, "title": "dota", "imgurl": "asd.com", "description": "", "hints": [ { "date": "2016-04-26 22:50:12.6069011 +0430 IRDT", "description": "narinin" …
CallMeLoki
  • 1,281
  • 10
  • 23
0
votes
1 answer

Querying a mongo DB collection into a struct

Defining this struct type SymbolMCAddrPort struct { ID bson.ObjectId `bson:"_id,omitempty"` Symbol string MCAddr string MCPort int } session, err := mgo.Dial("10.0.0.61") if err != nil { …
Ivan
  • 7,448
  • 14
  • 69
  • 134
0
votes
1 answer

Golang Maps: How to strip out empty fields automatically

Given the following struct... package models import ( "time" "gopkg.in/mgo.v2/bson" "github.com/fatih/structs" ) type User struct { Id bson.ObjectId `json:"id,omitempty" bson:"_id,omitempty"` Name string …
j3d
  • 9,492
  • 22
  • 88
  • 172
0
votes
1 answer

Golang & mgo: How to create a generic entity with common fields like _id, creation time, and last update

Given the following struct: package models import ( "time" "gopkg.in/mgo.v2/bson" ) type User struct { Id bson.ObjectId `json:"id" bson:"_id"` Name string `json:"name" bson:"name"` BirthDate time.Time …
j3d
  • 9,492
  • 22
  • 88
  • 172
0
votes
1 answer

too many arguments in call to Find mgo

I was trying to search a collection with multiple field conditions using $elemMatch operator. Then I encountered an error "too many arguments in call to c.Find". Document structure is as follows:- { "_id" : ObjectId("56cfca4bf23e4e2859257425"), …
Arjun Ajith
  • 1,850
  • 5
  • 21
  • 46
0
votes
1 answer

How to add more fields to an array in Mongodb, Go?

These are my Mongodb document structs. type Company struct { Id bson.ObjectId `bson:"_id,omitempty"` Company_name string Admin UserMinimal Process []ProcessItem } type ProcessItemMinimal struct { Id …
Arjun Ajith
  • 1,850
  • 5
  • 21
  • 46
0
votes
1 answer

Defining a MongoDB Schema/Collection in mgo

I want to use mgo to create/save a MongoDB collection. But I would like to define it more extensively (for e.g to mention that one of the attribute is mandatory, another one is of an enum type and has a default value). I have defined the struct like…
Dhanush Gopinath
  • 5,652
  • 6
  • 37
  • 68