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

how i get a session in mongodb with golang

I need to use the method CollectionNames() in order to list all the collections of a database. I will have to create a session in mongoDB: sess := ... // obtain session db := sess.DB("") // Get db, use db name if not given in connection url names,…
grafeno30
  • 479
  • 1
  • 5
  • 17
0
votes
1 answer

Use $push operator on document with mongoDB GODriver without creating separate arrays

I currently have some GO code that looks like this: _, err = swapStruct.ReferenceCollection.UpdateByID(ctx, swapStruct.ReferenceID, bson.D{ {"$push", bson.D{{"students", objIDs}}}, }) to insert an array of objectIDs, to a specific…
cordmana
  • 121
  • 3
  • 12
0
votes
0 answers

MongoDB Query To Compare timestamp with nested object timestamp

I have documents of the below structure: { "_id":{ "$oid":"6145b4405df7711fe1e2f3e0" }, "name":"Testing1", "description":"Testing Project1", "created_at":{ …
NicK
  • 27
  • 1
  • 9
0
votes
1 answer

Unable to Query MongoDB

Mongodb query: db.products.aggregate([ { $match : { "_id" : ObjectId("60d95b5ab861ccc04fd4b598") } }, { $project: { title : "Test Product 10", offers: { …
0
votes
1 answer

mongodb go: `mongo: no documents in result`

I have a pretty simple entry in my mongoDB database: {"_id":{"$oid":"609b15511a048e03dda05861"},"password":"test_password","answer":"test_answer"} And when I use filter parameters in the Atlas UI, I am able to pull up results. Filter: {"password":…
Patrick Collins
  • 5,621
  • 3
  • 26
  • 64
0
votes
0 answers

Querying first and last name with golang and mongo

I'm having some problems with querying the first and last name with go and mongo, basically if I search for "Jonh " (with the whitespace) it doesn't work and "John Doe" neither, but if I search "John" or "Doe" it works. func (user User) Prepare()…
Brunaine
  • 1,178
  • 2
  • 16
  • 24
0
votes
1 answer

Update mongo document

I have a mongo document that contains an array of clients. I want to be able to update a clients name by their userid. I have code below so far. When I run it it get multiple write error. There is only one document with that _id in my database. How…
Julia.T
  • 129
  • 2
  • 10
0
votes
1 answer

How to persist a file (much less than 16MB) in MongoDB using official go-driver

I'm trying to persist some files in MongoDB. Not interested in GridFS as files are always less than 256KB. It seems difficult to find any good example on how this typically is done. What I do is open temporary file for reading to get an io.Reader…
Michael B.
  • 31
  • 2
0
votes
1 answer

If slice exists and if it contains at least one specific variable set to true

I am trying to check if the slice of subscriptions exists, and also if it contains at least one variable called premium with the value of true. If so it should return, if not it should not return. Currently it is returning the object in the…
John
  • 47
  • 1
  • 8
0
votes
0 answers

How to set TTL Indexes in Mongodb document using mongo-go-driver?

How do I set TTL indexes in a document using "mongo-go-driver"? suppose here is my document model: type Session struct { ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"` AccessToken string …
Abid
  • 477
  • 1
  • 4
  • 15
0
votes
0 answers

Mongo go driver - giving key mismatch error while connecting with ssl enabled and encrypted key

I'm getting following error while trying to connect to mongodb server from golang application kubernetes pod. Error: tls: private key does not match public key I'm using mongo-go-driver version 1.4.1 Key is RSA encrypted. -----BEGIN RSA PRIVATE…
user81239
  • 1
  • 2
0
votes
0 answers

Using an opaque ID type in place of primitive.ObjectID

In a db package, I don't want to expose MongoDB's primitive.ObjectID type as part of its public API. Instead, I want to define type Id interface{} within the db package and expose that. Since the driver doesn't know how to transform the database's…
TJ Mazeika
  • 942
  • 1
  • 9
  • 30
0
votes
0 answers

Ways to create mongodb index in Golang

I currently create an index by: In package db: // CreateUniqueIndex create UniqueIndex func CreateUniqueIndex(collection string, keys ...string) { keysDoc := bsonx.Doc{} for _, key := range keys { if strings.HasPrefix(key, "-") { …
The questioner
  • 724
  • 10
  • 21
0
votes
0 answers

Is there an issue with BulkWriteResult on mongodb 3.4.1

Steps: Make the collection empty Try to bulk write around 3k+(3237 exact) records (all having UpdateOne model) in mongodb using go.mongodb.org/mongo-driver v1.3.4. Issue: For mongodb 3.4.1 it is returning me BulkWriteResult with only upserted…
0
votes
1 answer

check field exits,compare int value using go mongodb

I am using golang as backend with mongodb.I want to perform below code "$match" : bson.M{ "emp_dept": "xyz", "skills": "asd", "emp_del_status": bson.M{"$exists": true, "$eq": 0}, // emp account is active } My…
Rajandeep Kaur
  • 185
  • 1
  • 9