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,…
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…
I have documents of the below structure:
{
"_id":{
"$oid":"6145b4405df7711fe1e2f3e0"
},
"name":"Testing1",
"description":"Testing Project1",
"created_at":{
…
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":…
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()…
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…
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…
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…
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 …
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…
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…
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, "-") {
…
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…
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…