Getting all data from mongodb compound collection with filter in golang

I try to make get all data with Name field where I specify in API Request Body. I made a filter for .Find() function. But I can’t get any result (response body says null, No errors at all). You can see my model file and other parts of the code at bottom. Controller: func GET_FormByPatientFullName(ctx… Read More Getting all data from mongodb compound collection with filter in golang

Is there a way that can find one document and clone it with changing id/value in mongodb with Go

suppose I have code like this: var result bson.M err := coll.FindOne(context.TODO(), filter).Decode(&result) if err != nil { panic(err) } // somehow I can change the _id before I do insertOne if _, err := coll.InsertOne(context.TODO(), result); err != nil { panic(err) } is there a way I can insertOne without knowing the data struct?… Read More Is there a way that can find one document and clone it with changing id/value in mongodb with Go

Find a document via mongo-driver golang with nested array

I’m trying to do a basic query that searches for a document where a specific value is inside an array. Lets take the following example: { "metadata": { "tenant": [ "tenant1", "tenant2", "tenant3" ] } } filter := bson.M{"metadata": bson.M{"tenant": "tenant1"}} collection := mongo.Database(DB).Collection(Collection) result := collection.FindOne(context.Background(), filter) The result here is empty, I tried… Read More Find a document via mongo-driver golang with nested array

Mongo Aggregate – $addFields with multiplication

I’m using the official mongo driver on golang and trying to aggregate. I want to sort entries based on the multiplication of currency and salary. import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) func main () { //… aggregatePipeline := bson.A{} aggregatePipeline = append(aggregatePipeline, bson.D{{Key: "$addFields", Value: bson.D{{Key: "trueSalary", Value: bson.D{{"$multiply", bson.A{"salary", "currency"}}}}}}}) aggregatePipeline = append(aggregatePipeline, bson.D{{"$sort",… Read More Mongo Aggregate – $addFields with multiplication