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

Golang interfaces to simplify dependencies?

Hmmm, I'm having a problem wrapping my head around interfaces. So I am using a Go package for handling my mongodb stuffs, but I don't want to import that package into every model and what not. I'd like to keep as many of my sub packages (like…
macb
  • 41
  • 1
  • 7
0
votes
2 answers

Creating a query with mongoDB and mgo

I have a collection of mongoDB entries like the one below... { "_id": ObjectId("4e2a4ca7f21a81331f0006c3"), "users": { "bob": 1375496448, "alice": 1375496448 }, ...other values... } I am looking for a simple query for me to find all…
Matt Olan
  • 1,911
  • 1
  • 18
  • 27
0
votes
1 answer

Using mgo for nested document fields

I am using Golang with mgo driver for mongodb. According to example at http://labix.org/mgo everything works great. But I can not find any documentation how mgo supports "dot notation" to be able to set and remove nested fields. So, how can I…
jurka
  • 12,945
  • 3
  • 22
  • 20
-1
votes
2 answers

Golang GlobalSign mgo Query in MapReduce

import "github.com/globalsign/mgo" job := &mgo.MapReduce{ Map: "function() { emit(this.name, 1) }", Reduce: "function(key, values) { return Array.sum(values) }", Out: "res", } _, err = c.Find(nil).MapReduce(job, nil) How to add…
yodhevauhe
  • 765
  • 3
  • 11
  • 33
-1
votes
1 answer

How to make sure goroutine fully runs before exiting

I have a function calling a go routine that calls additional functions within it. However, those go routines are exiting before being completely finished. How would I make sure all the underlying code within the function (migrateUserHelper) runs…
pavbagel
  • 611
  • 2
  • 6
  • 17
-1
votes
1 answer

Cast emtpy interface to its equivalent type in Golang

Convert dynamic interface to its equivalent type. For example if value is int it should return int and if is string so it return int. Code example: var options = bson.M{} for _, val := range conditions { var attr, operator, value interface{} …
engrhussainahmad
  • 1,008
  • 10
  • 19
-1
votes
1 answer

Aggregate query in golang

I need to write a query in golang with mgo, here's the query in the mongo: db.some.aggregate([ {$match: { "data.id": "11111" }}, {$project: { _id : 0, url : { $concat: [ "https://www.someurl.com/","$data.aID" ]}, …
-1
votes
2 answers

mongodb mgo custom _id

I have used this method to create / insert a document: document5=({"_id": {"date" : 23, "hour" : 11}, "value" : {"avg_cpu" : 2.558333333333333, "avg_cpu_rate" : 18.419999999999998} })db.userdetails2.insert(document5) which resulted in this: { …
-1
votes
2 answers

Is there a way to get slice as result of Find()?

Now I'm doing: sess := mongodb.DB("mybase").C("mycollection") var users []struct { Username string `bson:"username"` } err = sess.Find(nil).Select(bson.M{"username": 1, "_id": 0}).All(&users) if err != nil { fmt.Println(err) } var myUsers…
Игорь
  • 77
  • 2
  • 6
-1
votes
1 answer

What is the correct way to save post data (with integer and string values) in the database golang?

I've the following golang code: package main import ( "github.com/gin-gonic/gin" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" "log" "time" ) func main() { router := gin.Default() router.POST("/save-address", SaveAddress) …
Swati
  • 83
  • 1
  • 14
-1
votes
1 answer

Sending chunked files to save in mongodb

I have 2 different servers for example (Server 1 , Server 2), In the first server I have golang app which splits files and sending to second server which should save in mongodb via mgo.v2 Server 1: func mainHandle(rw http.ResponseWriter, rq…
-1
votes
1 answer

I think my Go server is killing my Mongo servers

So long story short, I have many servers across 3 AWS regions. In an effort to reduce servers, which are written in Node, I've rewritten them in Go. To my delight and surprise 1 Go server can handle what 10 Node servers handle with lower CPU…
reticentroot
  • 3,612
  • 2
  • 22
  • 39
-1
votes
2 answers

Query where sum of two fields is less than given value

I am using Go language and MongoDB with mgo.v2 driver and I have struct like type MarkModel struct { ID bson.ObjectId `json: "_id,omitempty" bson: "_id,omitempty"` Name string …
PaolaJ.
  • 10,872
  • 22
  • 73
  • 111
-1
votes
2 answers

How to write insert golang code?

Here Is my json file and i want to insert the data using golang and mgo in this json format [{ "_id" : ObjectId("57307906f051147d5317984e"), "dateAdded" : " 20015-11-10 23:00:00 +0000 UTC" "firstName" : "chetan", "lastName" :…
Chetan Kumar
  • 328
  • 1
  • 4
  • 18
-1
votes
1 answer

getting fields blank in golang mgo

I was trying few exapmles using beego with mongo. you can find my source at : https://github.com/wsourabh/bapi but while calling the v1/accounts/:id I am always getting the response as curl -v…
Sourabh Jain
  • 55
  • 1
  • 4
1 2 3
42
43