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

MongoDB is not marshaling a value before storing it

I'm using a custom JSON marshaller/unmarshaller for a mapping between integers and strings in Go. The problem is that values are being stored in the database as integers instead of strings. In the example below, I would expect this to be stored in…
Scott Deerwester
  • 3,503
  • 4
  • 33
  • 56
0
votes
1 answer

mgo collection.Find(nil).All(&users) not working

I'm having the next issue.. I can't get all records from my mongo database (running in a docker containner), here is my really simple code: type User struct { Email string `json:"email" bson:"email"` Pass string `json:"pass"…
Gerardo Tarragona
  • 1,185
  • 4
  • 15
  • 28
0
votes
1 answer

Filter a collection but sort on inner property

Considering that I have a collection of documents like below and I want to get information returned as follows: Select all the entries from a campaign with campaignID = 12, sort by entries.questionscorrect in descending order with a limit of 10. I…
jim
  • 8,670
  • 15
  • 78
  • 149
0
votes
0 answers

Check object value exist in mongodb document in golang using mgo package

I need to check that object with FIELD value X already exists in mongo db using mgo package in golang. I already use $exists, that will find objects with FIELD no matter what its value. But I only need to know that object already is in db with value…
Sandun Priyanka
  • 591
  • 7
  • 24
0
votes
1 answer

Can i aggregate two mongodb queries in one query using golang (mgo)?

I use golang and mgo, mongodb version is 3.2.9 For example i have two documents in one collection: {"groupId" : 4, "name" : "email", "value" : "11@11.com"} {"groupId" : 4,"name" : "phoneNumber","value" : "000000000"} I know phoneNumber (value…
0
votes
1 answer

Ho to bind to slice values in go (gin) form?

Using go and gin-gonic, I'd like to post a simple form containing two tag fields and then save it to mongodb. Here is the form:
Karlom
  • 13,323
  • 27
  • 72
  • 116
0
votes
1 answer

Mongodb, golang. Can i count an slice/map without loading data into memory?

In my collection labs I have: { "_id" : ObjectId("57e602ada35ea4db6e4eee27"), "areas" : [ "nanotech", "robotics" ] } My query is: db.labs.find({"_id" : ObjectId("57e602ada35ea4db6e4eee27")},{areas:1}) What I want is to…
omgj
  • 1,369
  • 3
  • 12
  • 18
0
votes
2 answers

Querying document property using struct as find parameter

Problem description I try to find documents stored in MongoDB using GO Current state For testing purposes I created a small test program that inserts data into MongoDB and immediately tries to query: package main import ( "fmt" …
Sascha
  • 10,231
  • 4
  • 41
  • 65
0
votes
2 answers

save session in mongodb golang

I m using golang in the back end and mongodb is my database. I wanted to store the user session(betwen login and logout )of my web application in the mongodb for the persistence.Since there is provider available only for mysql not for mongodb,I…
Rajesh Kumar
  • 207
  • 1
  • 6
  • 12
0
votes
1 answer

Retrieving elements from embedded array in mgo (golang+MongoDB)

I'm using golang in the backend and mongoDB as database. When I try to retrieve documents from one of the embedded array I'm getting only one index of the embedded array in the result as the result. My struct is like this type ( Employee struct…
Rajesh Kumar
  • 207
  • 1
  • 6
  • 12
0
votes
1 answer

Golang find a value from a map of nested json data from MongoDB

I am trying to receive data from my MongoDB using MGO in a map of type []map[string]interface{} My JSON looks like this - { "_id":"string", "brandId":123, "category":{ "television":[ { "cat":"T1", …
Gaurav Ojha
  • 1,147
  • 1
  • 15
  • 37
0
votes
3 answers

Insert nested structures in MongoDb with Golang

I have a question regarding storage in MongoDB using mgo. My DB has this structure : { "Arrival": [ "04-09-2016" ], "Clicks": [ "56ffd41d9c8c9adf088b4576", "4f1dc63a7c2d3817640000a1" ], "Recherches": [ "érysipèle" ], …
Juanse
  • 95
  • 8
0
votes
0 answers

Get an array for a date range from an embedded document in a collection

So, inside a collection I have many documents, each document have embedded an array of documents, each of these documents inside the embedded array have many fields, among them, a "date time" field. What I want to do is to get an array for a date…
shackra
  • 277
  • 3
  • 16
  • 56
0
votes
0 answers

$lookup and insert in golang

How can I write a similar query in golang (mgo)? db.result.aggregate([{ $lookup: { from: "session", localField: "session.id", foreignField: "_id", as: "session_info" …
R.Rulle
  • 3
  • 1
0
votes
1 answer

How do I use MGO aggregation pipeline to find all embedded documents matching certain criteria

Lets say I have the following data in a Groups collection in MongoDB [ { “Group”: { “_id”: 1, “Requests”: [ { “_id”:1, “name”:”Request A” }. …
TheJediCowboy
  • 8,924
  • 28
  • 136
  • 208