mgo Questions

5

I'm writing a RESTful API in Golang, which also has a gRPC api. The API connects to a MongoDB database, and uses structs to map out entities. I also have a .proto definition which matches like for ...
Sapienza asked 17/7, 2017 at 22:49

2

Solved

I am new to GO language and I am using MongoDB with it. I am creating a backend for an application and its frontend on Angular 4. I want to check if collection exists or not. Here is my code and ...
Disposed asked 19/9, 2017 at 6:11

5

Solved

I have multiple packages under a subdirectory under src/, running the tests for each package with go test is working fine. When trying to run all tests with go test ./... the tests are running but...
Stanley asked 17/5, 2014 at 19:31

5

Solved

What I am looking is equivalent of Document.parse() in golang, that allows me create bson from json directly? I do not want to create intermediate Go structs for marshaling
Aberrant asked 30/9, 2016 at 6:45

4

Solved

I am trying to aggregate a batch of documents. There are two fields in the documents I would like to $push. However, lets say they are "_id" and "A" fields, I only want $push "_id" and "A" if "A" i...
Gagnon asked 6/4, 2018 at 6:51

3

Solved

So here is my question. I have an array which are stored the _ids of mongodbs objects. Whats the right way to retrieve them all in one query using the mgo and bson package? So if the array is like...
Toponym asked 17/10, 2014 at 15:22

10

Solved

The following is my MongoDB connection dial from GoLang. But it's returning a panic "server returned error on SASL authentication step: Authentication failed.". My username, password, hostAddrs and...
Blackmail asked 3/8, 2016 at 12:47

2

Solved

I have the following problem. I need to convert a structure to map[string]interface{} in order to perform an update in database (using mgo as driver for mongodb). Update For partially updating a do...
Approximation asked 10/5, 2014 at 15:55

2

Solved

I have two structs that represent models that will be inserted into a mongodb database. One struct (Investment) has the other struct (Group) as one of its fields. type Group struct { Base Name st...
Bisexual asked 14/6, 2014 at 4:14

3

Solved

Hi I have a collection named "my_sales" having fields product_name, price, sale_date. My doc looks like { "_id" : ObjectId("5458b6ee09d76eb7326df3a4"), "product_name" : product1, "price" : 200...
Durian asked 6/11, 2014 at 7:31

1

Solved

When I insert multiple documents with insert(docs...), Operation is failing & fails to insert documents if one duplicate key in a document exists in list of documents. How can I ignore this err...
Pournaras asked 2/3, 2020 at 3:38

2

Solved

I am new in golang and MongoDb. How can I delete a single document identified by "name" from a collection in MongoDB? Thanks in Advance
Desman asked 1/2, 2016 at 12:30

1

Solved

Long, long ago, when we were using mgo.v2, we created some wrapper functions that copied the session, set the read pref and returned that for consumption by other libraries, e.g. func NewMonotonic...
Carlycarlye asked 18/9, 2019 at 17:56

3

Solved

As I know, we can use > db['twitter-3'].find({}, {"text": 1}) to select all texts in collection. How can we use mgo to find specific field in golang? I tried var result []string err = conn...
Erl asked 29/6, 2015 at 13:5

3

Solved

I'm trying to insert some data in MongoDB using Go. Here is the data struct: type Entry struct { Id string `json:"id",bson:"_id,omitempty"` ResourceId int `json:"resource_id,bson:"resource_id"`...
Tiossem asked 11/5, 2014 at 23:59

1

I'm using *mgo.Session of MongoDB driver labix_mgo for Go, however I don't know if a session is closed. When I use a closed session, a runtime error will be raised. I want to skip the session copy ...
Yep asked 17/10, 2018 at 7:38

2

Solved

In MongoDB doing something like db.mycollection.find() returns all documents in a collection. When working in GoLang using the package labix.org/v2/mgo and I do for example: query := db.C("client...
Subtreasury asked 10/7, 2014 at 15:53

1

We have mongodb with mgo driver for golang. There are two app servers connecting to mongodb running besides apps (golang binaries). Mongodb runs as a replica set and each server connects two primar...
Dissentious asked 9/10, 2018 at 17:21

1

I am working on a project that uses combination of Go and MongoDB. I am stuck at a place where I have a struct like: type Booking struct { // booking fields Id int `json:"_id,omitempty" bson:"_i...
Cyanide asked 23/8, 2018 at 7:12

1

Solved

I have the following model: type UserModel struct { Id string `bson:"_id,omitempty"` CreatedAt *time.Time `bson:"createdAt,omitempty"` BasicInfo *UserBasicInfoModel `bson:"basicInfo,omitempty"`...
Pekin asked 26/5, 2018 at 12:22

2

Solved

I would like to run the following query in golang using mgo in a pipeline. {"key1" : 1, "$or" : [{"key2" : 2}, {"key3" : 2}]} I have looked everywhere, but I cannot find an example like this. I...
Hustings asked 14/11, 2014 at 14:31

2

Solved

I am trying to convert this JS MongoDB query into Go mgo query: var foo = "bar"; db.collection.find({"$or": [ {uuid: foo}, {name: foo} ] }); This is what I've got so far, but it doesn't work: c...
Mellar asked 5/12, 2014 at 19:39

1

Solved

I read this article and it has good guides for mocking MongoDB in Go. But there are some problems in Clone() and Copy() methods. I create this interfaces and structs: type ISession interface { DB...
Brocket asked 28/4, 2018 at 3:53

3

Solved

According to the documentation (http://godoc.org/launchpad.net/mgo/v2) you can obtain the ID of your "Upserted" document if you use the Upsert method. There is also an Insert method that does not ...
Halcomb asked 17/8, 2012 at 16:9

2

Solved

Suppose you have a workflow that consists of multiple embedded nodes of different types. Since nodes are of different types, I thought of using Golang interfaces here and came up with following: t...
Denishadenison asked 25/9, 2014 at 13:14

© 2022 - 2024 — McMap. All rights reserved.