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
-1
votes
1 answer

why variable is nil although I put there reference to object

I cannot figure out why after calling ConnectToMongo variable session is still nil. I would understand it if ConnectToMongo accepts not reference type like ConnectToMongo(session mgo.Session) but reference variable type *mgo.Session must be saved…
Maxim Yefremov
  • 13,671
  • 27
  • 117
  • 166
-1
votes
2 answers

Go compile error "undefined function"

I have the following pieces of code: Interface & function definition: package helper import "gopkg.in/mgo.v2/bson" // Defines an interface for identifiable objects type Identifiable interface { GetIdentifier() bson.ObjectId } // Checks if a…
Michel
  • 303
  • 2
  • 15
-2
votes
1 answer

The most improved way to get all likes for each post in MGO?

Likes have different collection, so do Posts. But, maybe it is more efficient and green that: just getting all posts and when users hover on posts fetching likes or when intersection api is triggered visible on the screen, fetching likes, Should I…
Bitfinicon
  • 1,045
  • 1
  • 8
  • 22
-2
votes
1 answer

Which library is More Efficient "gopkg.in/mgo.v2" or "go.mongodb.org/mongo-driver/mongo"

I am using Golang as backed language with mongodb database and also new to this language.I have used both libraries "gopkg.in/mgo.v2" and "go.mongodb.org/mongo-driver/mongo" to perform all CRUD oprations. My Question is which one is more efficient…
Rajandeep Kaur
  • 185
  • 1
  • 9
-2
votes
1 answer

Implement MongoDB shell in GO

I have data in MongoDB as tree structure model. Here is my data structure: Here is my Mongo shell to create…
ThanhLam112358
  • 878
  • 1
  • 20
  • 51
-2
votes
1 answer

Get a slice of json string from mongo using golang

I am trying to get a slice of json text from mongo using the below code in golang var a []string err := col..Find(nil).Select(bson.M{"_id": 0}).All(&a) I get the error Unsupported document type for unmarshalling: string May I know the right way to…
DoIt
  • 3,270
  • 9
  • 51
  • 103
-2
votes
1 answer

What's the downside of using global mongo (mgo) database in golang?

Are there any downsides if we use a global variable to handle database operations instead of passing it as an argument to functions and methods or storing it as a field in structs? What are these downsides (if there are)? Let's say we create a…
Ali Padida
  • 1,763
  • 1
  • 16
  • 34
-2
votes
1 answer

Golang Cannot recover from panic mgo.DialWithInfo

I tried to unit test connection to MongoDB using mgo.DialWithInfo function (in the failure case). mgo.DialWithInfo does not return an error but panics instead. I tried to add recovery logic to recover from the panic without success. My questions…
Gibi
  • 451
  • 1
  • 3
  • 12
-2
votes
1 answer

How to define mongodb Text Indexes in mgo with weights

I'm trying to create text indexes with weights but I couldn't figure out how to do by reading API docs. How can I build indexes as below in mgo. db.products.createIndex({ "primaryCategoryIndexes": "text", "secondaryCategoryIndexes": "text", …
Lupus
  • 1,519
  • 3
  • 21
  • 38
-2
votes
1 answer

Go command returns not found but works in terminal

I am trying to remove a record from MongoDB using the following line of Go code: mg.collection.Remove(bson.M{"id": 1}) this command returns a not found error but the following piece of codes works without issue in the terminal and…
jim
  • 8,670
  • 15
  • 78
  • 149
-3
votes
2 answers

Getting error while deleting the key value from array of objects

I am getting the following error while deleting from key from array of JSON objects using Go. Error: repository/orderRepository.go:394:11: first argument to delete must be map; have interface {} repository/orderRepository.go:395:11: first…
user_agent
  • 65
  • 9
-3
votes
2 answers

JSON tag is ignored when inserting struct/document into mongo (through mgo)

This is what the struct looks like This is what the documents look like in Mongo.
Lukas Süsslin
  • 553
  • 1
  • 3
  • 12
-3
votes
1 answer

How to sum the values of fields?

I have structs like this { "actionName": "add_new_paint_layer", "countUse": 1, "sources": "smth" }, { "actionName": "clear", "countUse": 1, "sources": "smth" }, { "actionName":…
djkah11
  • 446
  • 5
  • 21
1 2 3
42
43