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 =…
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",…
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?
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 (
…
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…
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…
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…
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 _,…
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…
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…
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…
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"
…
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…
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…
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…