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

Updating certain user fields

Requests to my API contain an ID (required) and optional others fields such as name, email and username. { "id" : "12345", "name" : "Bob", "email" : "test@example.com" } After binding the request to a struct user if there isn't a user…
tommyd456
  • 10,443
  • 26
  • 89
  • 163
0
votes
1 answer

mgo find convert a single value array to string

This is part of my collection schema in mongodb: { "_id" : ObjectId("55e1eef5255da6d384754642"), "name" : [ "Web, Mobile & Software Dev", "Movil y desarrollo de software" ] } { "_id" : ObjectId("55e1f2d0255da6d38475464b"), "name" : [ "IT &…
Raul Gomez
  • 620
  • 7
  • 15
0
votes
1 answer

how to search a key of embed object in mgo?

query:=bson.M{"relationship.from": bson.RegEx{"\\d+8.*", ""}} c.Find(query).All(&users) above code returns empty set, but the collection looks like: {"name" : "test","phone": "13xxxx" "relationship":{"from":1982, "to": 1998}} {"name" : "test2",…
benyu
  • 121
  • 8
0
votes
1 answer

Set MongoDB write concern through mgo driver

I have a Go client that repeatedly inserts data into MongoDB for 1 minute. I don't want the writes to be acknowledged to the client until they are replicated to the secondary of my primary-secondary-arbiter replica set, so I specified majority write…
0
votes
1 answer

Logging in with username or email address

I'm trying to improve a block of code in my Go app which handles logins. It receives a login value and a password value and then checks either the username field or the email field in the database to see if a user can be found. If the login contains…
tommyd456
  • 10,443
  • 26
  • 89
  • 163
0
votes
2 answers

mgo: Query ObjectId for range of time values

Ok, say you have a number of posts type Post struct { Id bson.ObjectId `bson:"_id,omitempty"` } and each post of course has a unique id that was created at a certain time. I can get the time value with post.Id.Time(). However how do I query for…
user2312578
0
votes
1 answer

mgo NewObjectId corrupt on insert

If I generate a new object id for a document in mgo: obId := bson.NewObjectId() and then insert it, it ends up in mongo (looking via the cli) as "_id" : "U�`�\u0006@�\rU\u0000\u0000\u0001" When it should be "_id" :…
byrnedo
  • 1,415
  • 10
  • 12
0
votes
1 answer

Can not retrieve value using mgo when the key contains uppercase

One data from mongoDB is { "_id" : ObjectId("5536def4e4b0644323e219a8"), "title" : "The Title", "description" : "The Description", "timeStamp" : "21/04/2015", "category" : "news", "url" : "http://www.example.com", …
Wyatt
  • 1,357
  • 5
  • 17
  • 26
0
votes
1 answer

Does Mgo cache connection strings?

My Go application has been connecting to a MongoDB (hosted on Compose.io) using MGO with no issues. Today I decided to delete this database and add a different one (again using Compose). I updated the connection string. So I connect using: db, err…
tommyd456
  • 10,443
  • 26
  • 89
  • 163
0
votes
1 answer

How to prevent to multiple goroutines inserts document in persons collections if already exists person with same name and last name?

How to prevent multiple goroutines to insert document in persons collections if already exists person with same name and last name ? type Person struct { Id bson.ObjectId `bson:"_id"` Name string …
PaolaJ.
  • 10,872
  • 22
  • 73
  • 111
0
votes
1 answer

query by date in mongodb

I'm able to insert an entry into MongoDB using the golang driver gopkg.in/mgo.vs and gopkg.in/mgo.vs/bson but I'm not able to pull it out. In the mongo shell, if I do db.Items.find({ date : 1428762411980 }) it shows me the entry that I just…
BrainLikeADullPencil
  • 11,313
  • 24
  • 78
  • 134
0
votes
1 answer

Update query in MGO driver, works with bson.M, but does not work with custome structure

Mgo and golang question. I run into problem again. I try to update record in the database, but running simple command visitors.UpdateId(v.Id, bson.M{"$set": zscore}); where zscore is a variable of type Zscore, does not work. However if I manually…
Luke
  • 61
  • 6
0
votes
1 answer

mgo query returns "EOF" for large datasets

I want to perform a query that returns some data from my MongoDB server, but when the amount of data becomes big I get an "EOF" error from the c.Find().All() query. Basically I have: activeData := []DataEntry{} activeDataQuery :=…
Lars
  • 1,006
  • 1
  • 9
  • 29
0
votes
1 answer

gorilla/schema and mgo/bson.ObjectId

Here's a bit of a chicken and egg problem. In a HTML template, a form, bson.ObjectId needs to be rendered with {{mytype.Id.Hex()}} e.g.
user2312578
0
votes
1 answer

Golang Mgo populate nested structs by ID (Mongodb)

Using mongoose with NodeJs for document population to simulate joins is very common. I'm trying to understand how to achieve something similar with go and mgo. type User struct { Id bson.ObjectId `json:"_id" bson:"_id"` UserName…
TheBigC
  • 605
  • 3
  • 9
  • 17