Questions tagged [mongo-go]

Official MongoDB Go driver

Official driver page: https://docs.mongodb.com/ecosystem/drivers/go/

It is available here: https://github.com/mongodb/mongo-go-driver

Documentation (godoc): https://godoc.org/github.com/mongodb/mongo-go-driver

It was announced here: Considering the Community Effects of Introducing an Official MongoDB Go Driver

229 questions
1
vote
2 answers

What are the default values of clientOptions for mongo-go-driver?

I was trying to search for default values for clientOptions for mongo-go-driver. I am trying to initiate new client in following way: opts := options.ClientOptions{} opts.ApplyURI(connectionURI) sharedConnection, err =…
1
vote
1 answer

Why mongo-go-driver aggregation result object keys returned as "Key"

I want to group some data with mongo-go-driver using aggregate, but the json result confused me, because the row key replaced with "Key" and and the real key become the "Key"s value var result primitive.A pipeline := mongo.Pipeline{{{"$group",…
Mr Syhd
  • 73
  • 4
1
vote
0 answers

How to bson.UnmarshalExtJSON to parse Time string into ISODate

I have raw json: { "@timestamp":"2019-05-05T19:54:00.455+08:00" } and I have defined struct: type A struct { Timestamp string bson:"@timestamp" } How to realize it with bson.UnmarshalExtJSON?
ermazi
  • 11
  • 1
1
vote
1 answer

How to import go's mongo-driver bson

I installed the mongo go driver with go get go.mongodb.org/mongo-driver/..., but whenever I try to use bson.EC or bson.NewDocument as seen here, I get errors: undefined: bson.NewDocument and undefined: bson.EC. What am I missing here? import ( …
Kelly Flet
  • 514
  • 2
  • 5
  • 23
1
vote
2 answers

Mongo-Go-Driver Failing to Connect

So I am trying to use https://github.com/mongodb/mongo-go-driver to connect to a mongo database in golang. Here is my connection handler: var DB *mongo.Database func CreateConnectionHandler()(*mongo.Database, error){ fmt.Println("inside…
Peter Weyand
  • 2,159
  • 9
  • 40
  • 72
1
vote
1 answer

Golang mongo-go-driver Beta 1 , using greater than operator

I have been trying to get records greater than an _id provided The code is below filter = bson.M{"_id": bson.M{"$gt": "5c1760b4bd421c09e0f3140c"}} cur, err := collection.Find(ctx, filter, &options) But iam always getting null values. I think i need…
nobody
  • 29
  • 4
1
vote
0 answers

cannot transform (struct containing pointer) type to a *bsonx.Document

I've recently started using the official mongo-go-driver (github.com/mongodb/mongo-go-driver) and it seems that I cannot use pointers in my structs -> ex.: type example struct { hello *string } If you initialize this struct and try to insert it…
1
vote
3 answers

Convert a string slice to a BSON array

I am trying to insert an array into a MongoDB instance using Go. I have the [] string slice in Go and want to convert it into a BSON array to pass it to the DB using the github.com/mongodb/mongo-go-driver driver. var result bson.Array for _,…
max
  • 677
  • 1
  • 9
  • 34
1
vote
1 answer

How to parse extended JSON Date in aggregation pipeline using ParseExtJSONArray() in mongo-go-driver

I've got a collection with a Date field: { "_id" : ObjectId("5b92b359ddceef5b24502834"), "dateTimeGMT" : ISODate("2018-08-22T09:29:25.000Z"), yada, yada, yada } I'm trying to find by date in a $match aggregation stage with the…
1
vote
1 answer

How to page a cursor in official mongo-go-driver

Inspecting the interface Cursor in mongo-go-driver: https://github.com/mongodb/mongo-go-driver/blob/master/mongo/cursor.go#L37 There's no Limit or Skip functions. How can I page the results? I think I will face the same problem when trying to Sort…
rsan
  • 1,887
  • 2
  • 17
  • 23
0
votes
1 answer

Golang MongoDB delete multiple items in one query

I have a match table in my DB and I need to delete multiple items from it and I was wondering if there is a way to do this using a single query. I get deleteList of type []primitive.ObjectID in my Go code. deleteList is basically a list of match.id…
Marius
  • 537
  • 1
  • 6
  • 23
0
votes
1 answer

Is mongodb client driver concurrent safe?

In the below code from codebase, mongodb client is created(as shown below): import ( "context" "time" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" …
overexchange
  • 15,768
  • 30
  • 152
  • 347
0
votes
2 answers

How to count number of documents in aggregate pipeline query?

So basically I am performing a query using an aggregation pipeline. In one of the stages, I want to count the number of documents BUT rather than passing the count value to next stage, I'd like to pass the count AND the document(s) that was the…
darkstar
  • 829
  • 11
  • 23
0
votes
2 answers

Search on 2 properties in MongoDB query

query := bson.M{ "nombre": bson.M{"$regex": `(?i)` + search}, // me va a buscar los nombres que contengan search } I had this code to do a search in my DB where I have name and surname. I want this query to be valid for all those instances in…
0
votes
1 answer

How Do I Structure MongoDB To Query By Date Time Per Minute?

I am trying to store the price of stocks price per minute, so I can easily return results based on the minute date time per minute interval and store historical data, so i can query like last 24 hours, last 30 days etc (please also let me know if…
uberrebu
  • 3,597
  • 9
  • 38
  • 73