I am using Golang/Fiber + Mongo driver.
I have simple struct for blog post:
type Post struct {
ID primitive.ObjectID `json:"_id" bson:"_id,omitempty"`
Title *string `json:"title" bson:"title"`
Slug …
MongoDB cluster(free) paused only after a couple hours of inactivity (as opposed to the stated 7 days for the free cluster).
I have tried to resume using mongosh and through my Go code but it still does not work. This is my second time encountering…
I'm trying to configure a pool connections to my Go program with mongodb, where I set minPoolSize to 20 connections using mongodb go driver. Something like that:
cli, err := mongo.Connect(ctx,…
I'm writing a Go app using mongo-driver to connect to the mongo replica set.
I've noticed that mongo.Connect is not actually connect to the database.
Even if I've shutdown the mongod instance, mongo.Connect sill able to pass through.
However, when I…
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 :=…
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"
…
One of my tests for a function that performs increments using the MongoDB driver for Go is randomly breaking in an unexpected way. Here's what the test does:
Create a proxy (with toxiproxy) to a local MongoDB instance.
Disable the proxy, so the…
There is a mongodb cluster (1 master 2 replicas)
Updating records in a larger number and for this used BulkWrite, need to call next BulkWrite after replicas caught up master, need to make sure that the replicas have already caught up with the master…
I'm trying to aggregate with the group operator and multiples values
I made this query in MongoDB :
db.Modules.aggregate([{$group: {_id: {"module":"$module","host":"$host"},"status":{$last:"$status"}}}])
I use package : go.mongodb.org
I want to…
I have a a structure with two keys as follows:
{
"cannot_be_empty": "hello",
"can_be_empty": "world"
}
Right now I set the index to be a combination of can_be_empty and cannot_be_empty.
db.collection.Indexes.CreateOne(IndexModel{{Keys:…
From my frontend, users can apply filters based on date range or purpose, or both. How do i generate the MongoDB filter so that if users pass in date range, it only uses that as a filter? If it is only purpose, it only uses purpose and if it is…
I'm trying to retrieve the last inserted document using FindOne as suggested elsewhere:
collection.FindOne(ctx, bson.M{"$natural": -1})
Get last inserted element from mongodb in GoLang
Here is my example:
var lastrecord bson.M
if err =…
I'm trying to update a document in MongoDB with mongodb/mongo-go-driver. From its doc, one document can be replaced with:
var coll *mongo.Collection
var id primitive.ObjectID
// find the document for which the _id field matches id and add a field…