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

How to retrieve unstructured form of data from mongo using go map

I'm trying to retrieve data using go map. The data in mongo is like "_id" : ObjectId("56bf128f5a9a6a0ebfdd5075"), "deadLine" : { "Start_time" : ISODate("2016-05-24T00:00:00Z"), "End_time" : ISODate("2016-05-29T00:00:00Z") }, …
Sohail Shaikh
  • 45
  • 1
  • 6
0
votes
1 answer

How do i combine list of bson.M elements into a single bson.M in mongo in golang?

lstMap := make([]interface{}, 0) lstMap = mongoOps.AddToBsonMap(lstMap, bson.M{"$inc": bson.M{"Google.ab.Value": 1}}) lstMap = mongoOps.AddToBsonMap(lstMap, bson.M{"$inc": bson.M{"Google.ab1.Value1": 1}}) func (o *MongoOps) AddToBsonMap(lstMap…
user5160937
0
votes
1 answer

Update mongo transaction by field Name like in given example

I am using labix as driver and I want to make transactions over couple collections, I found link http://blog.labix.org/2012/08/22/multi-doc-transactions-for-mongodb and I want to update in collection Owner and Employer not by Id but by Name field in…
PaolaJ.
  • 10,872
  • 22
  • 73
  • 111
0
votes
1 answer

Golang jsonapi requires string or int but mongo needs bson.ObjectId

Playing with go and the following packages: github.com/julienschmidt/httprouter github.com/shwoodard/jsonapi gopkg.in/mgo.v2/bson I have the following structs: type Blog struct{ Posts []interface{} } type BlogPost struct { Id…
noahtkeller
  • 165
  • 2
  • 8
0
votes
1 answer

How would I select all embedded documents of the same type in mgo Mongodb?

I have a go application which uses mgo/mongodb. I'm using embedded documents rather than relational ones. So I have... (some code redacted for brevity). type User struct { Id bson.ObjectId `bson:"_id,omitempty" json:"id"` Name …
Ewan Valentine
  • 3,741
  • 7
  • 43
  • 68
0
votes
1 answer

Go nested object with mgo adapter

I'm working on a project that based on MongoDB data structure. Our objects that stored inside the database looks like this: { "_id" : ObjectId("567a877df1c7720bea7c2f51"), "username" : "dog", "type" : "regular", "data" : { "full" : { …
Daniel Chernenkov
  • 715
  • 1
  • 7
  • 23
0
votes
2 answers

Golang, mgo update details for a user

I have been having some trouble updating a user on a mongodatabase. Basically I want to select the user by username and than edit its details. I am using Gorilla Mux and mgo to connect with MongoDB. Here is the code: func ViewUserHandler(w…
user3212497
0
votes
1 answer

how to create bson map based on input

I am building a bson map in golang using mgo library. I want to refactor some code to be able to avoid duplication. Consider this: bson.M { "$match" : bson.M{ "xyz" : "abc", }, "$id_1" : value_1, …
SeattleOrBayArea
  • 2,808
  • 6
  • 26
  • 38
0
votes
1 answer

Golang MongoDb GridFs Testing

I have a rest API implemented using Gorilla Mux in Golang. This API uploads/downloads files from MongoDb GridFs. I want to write integration tests for my API. Is there a embedded MongoDb package with GridFs support in Go? How do we test APIs using…
suman j
  • 6,710
  • 11
  • 58
  • 109
0
votes
1 answer

MongoDB (Mgo v2) Projection returns parent struct

I have here a Building Object where inside sits an Array of Floor Objects. When Projecting, my goal is to return or count the number of Floor Objects inside a Building Object after matching the elements accordingly. The code is as…
William Yang
  • 759
  • 9
  • 30
0
votes
0 answers

Inserting arrays of Object IDs in mgo

So recently I've been trying to insert different types of data into structures using mgo, and I've ran into a bit of a snag. When trying to insert an array of object IDs, I can't seem to figure out that format if I were to populate that object ID…
Phlex
  • 401
  • 2
  • 6
  • 17
0
votes
1 answer

Error in vendoring of third party library(mgo.v2)

I am trying to have a local copy of current code base of mgo.v2. https://gopkg.in/mgo.v2 says to install using go get gopkg.in/mgo.v2. I forked it from https://github.com/go-mgo/mgo/tree/v2 and trying to install it from go get forked repo from git…
timedout
  • 541
  • 1
  • 4
  • 12
0
votes
2 answers

Create a function which returns a mongo collection with Golang and MGO

I'm new to GOLANG - I would like to reduce the complexity of the handlers in my GO API. I'm coming from a Node.js background! At the moment a route handler looks like this: func getCards(c web.C, w http.ResponseWriter, r *http.Request) { …
Chris
  • 3,004
  • 3
  • 21
  • 26
0
votes
1 answer

Mongodb queries on routines produces huge stack trace

I am doing lots of web calls to an api in a go program, and the results are stored in a database (using mgo). The api calls are done on separate go routines. On other routines, I am pulling the information out of the database and processing it,…
amlwwalker
  • 3,161
  • 4
  • 26
  • 47
0
votes
1 answer

Mgo (mongo for go) support for materialized paths?

With BSON and Mgo(rich mongodb driver for go), how would one approach implementing materialized paths? Materialized paths are documented here on the mongo docs. Materialized paths are designed to provide a tree-like structure for multiple levels of…
William Yang
  • 759
  • 9
  • 30