175,439 questions
0
votes
1
answer
40
views
In a MongoDB transaction, are index entries updated immediately when an indexed field is modified?
I'm working with MongoDB transactions (Node.js, replica set). Inside a transaction, I update a document in a way that changes the value of a field that is covered by an index. Later in the same ...
Tooling
0
votes
2
replies
33
views
Docker and MongoDB
My mongo database is contained in a docker image.
I use this command in order to run the docker container:
docker run -p 127.0.0.1:27017:27017 mongo:Version
and afterwards I do a mongorestore:
...
0
votes
1
answer
63
views
`Filters.eq(fieldName, value)` not actually creating `$eq` causes issues
I'm not sure if this is a MongoDB issue, an issue with the mongo-java-driver or if I'm doing something worng.
The issue is that MongoDB can behave differently in case there is a $eq operator or if a {...
2
votes
2
answers
85
views
MongoDB to Oracle insert runs in reverse date order
I have Python code in which I am reading data from MongoDB and insert it into a table in Oracle database. I have removed some parts of the code (importing libraries, connecting to MongoDB and Oracle, ...
1
vote
1
answer
77
views
MongoDB Go Driver v2: How to Marshal a Nil Custom Type as BSON Null?
I’m using MongoDB GoLang Driver v2 and I want to store a custom money type in MongoDB.
If the value is nil, I want the BSON document to store price: null.
Example document I want:
{
"name":...
Tooling
0
votes
0
replies
50
views
How to convert javascript object of mongodb based query to mongodb query as parse
So I have an MEAN stack application where user types query ( or copy from mongodb compass ) in a editor and I use nodejs in backend to perform that query ,
So I use codemirror editor to text codes , ...
0
votes
0
answers
50
views
How to update a large number of mongodb documents in a tree structure?
I'm using mongo db with payloadcms and I have tree like structure.
We have a collection called nodes. A node have children as array and a parent id.
Now I want to change the node status like marking ...
0
votes
0
answers
34
views
MongoDB/Pymongo giving random ServerSelectionTimeoutError messages
We're using Tornado-based services, which fork and then create DB connections. This was all working fine until we tried upgrading to python 3.11 (from 3.8) and using pymongo 4.8.0. Now, we very ...
-3
votes
0
answers
29
views
Express.js: "Cannot set headers after they are sent to the client" error with MongoStore sessions - page renders correctly Error [ERR_HTTP_HEADERS_ERR [duplicate]
I'm getting the error Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client in my Express.js application using MongoDB session store, but the page displays correctly in ...
0
votes
0
answers
53
views
Mongoose model throws validation errors even though payload is correct — document still gets created on first error
I'm building a guest creation API using Next.js (App Router), Zod, and Mongoose.
The problem:
Even though my frontend validation passes and I see the full payload in the console, the server throws ...
0
votes
1
answer
43
views
MongoTimeoutException in Testcontainers Integration Test : Open Liberty app attempts to connect to Kubernetes FQDNs instead of local alias
Title - MongoTimeoutException in Testcontainers Integration Test : Open Liberty app attempts to connect to Kubernetes FQDNs instead of local alias
I am writing integration tests for an Open Liberty-...
0
votes
2
answers
58
views
Can't connect to MongoDB Atlas (free tier)
I'm struggling to connect from my Rails deployment to an Atlas Cluster.
This is my MONGODB_URI:
mongodb+srv://JohnDoe:****@cluster0.*****.mongodb.net/XYZ_prod?retryWrites=true&w=majority
The ...
2
votes
1
answer
80
views
How to reduce logging level in mongodb/mongodb-atlas-local [closed]
Problem:
I'm using the mongodb/mongodb-atlas-local Docker image in our CI/CD pipeline for running tests. While the verbose logging is acceptable for local development, it becomes problematic in CI/CD ...
3
votes
1
answer
78
views
Mongodb timeseries collection can't query far far future records
Mongo can't bring records which are in far far future like 2394-10-20T16:10:23
now: 2025-11-17
Description:
I have a timeseries collection in mongo and here is the command to created it:
db....
Advice
1
vote
2
replies
70
views
Connecting to Mongodb from inside Docker container
I want to connect to my mongodb running on my localhost machine (dockerhost) from inside a docker container. For that I have to allow connections other than localhost. Unfortunetly when using --...
Advice
0
votes
1
replies
37
views
Is Mongoid 9 compatible with MongoDB 8.2?
Looking at the compatibility page, MongoDB 8.2 isn't listed as compatible. In practice, I suspect this page is updated less often than it should be, so I wonder if Mongoid is actually fully compatible ...
5
votes
1
answer
242
views
.NET 9 -> .NET 10: MongoDB query using array.Contains throws NotSupportedException
After upgrading from .NET 9 to .NET 10, a MongoDB query that used to work now throws a System.NotSupportedException during query execution. I'm looking for pointers whether this is a runtime change in ...
Best practices
0
votes
1
replies
57
views
Mongodb Using aggregates for advanced search
Trying to solve a conundrum I have in writing some queries.
I’ve traditionally used simple find operations (and cursor operations for paging functionalities), but need something more complex to ...
2
votes
0
answers
67
views
MongoDB 8.0: StaleDbVersion triggers shard-local majority write after step-up; fails with 2 data + 1 arbiter when one data pod is down [closed]
Environment
Deployment: Kubernetes (RKE2), Bitnami MongoDB Sharded Helm chart
MongoDB: 8.0.8
mongosh: 2.5.0
Topology:
Config servers: 3 (CSRS)
Mongos: 3
Shards: 3 shards total; each shard is a replica ...
1
vote
1
answer
54
views
Jest + Testcontainers MongoDB: Intermittent ECONNREFUSED errors running integration tests
Problem
Starting November 10th, my Jest integration tests began failing randomly with MongoDB connection errors. The tests use @testcontainers/mongodb v11.5.1 and mongodb v8.0.12.
Error:
...
0
votes
0
answers
55
views
MongoDb connection limit
I am running a MongoDb atlas M20 instance which should have a maximum of 1500 connections in its pool. It has 1 primary and two secondaries. If I look at the server stats I can see the connections are ...
2
votes
0
answers
56
views
PySpark/MongoDB Connector DataException: dataType 'struct' is invalid for 'BsonArray' during ETL
I am running a data ingestion ETL pipeline orchestrated by Airflow using PySpark to read data from MongoDB (using the MongoDB Spark Connector) and load it into a Delta Lake table. The pipeline is ...
0
votes
0
answers
57
views
MongoDB Atlas Timeout After Deployment Update — "ReplicaSetNoPrimary"
I updated my backend deployment (Flask app) with a new feature not related to database logic, and suddenly MongoDB Atlas connections no longer work. Before the update, everything was fine.
Local ...
2
votes
1
answer
85
views
How to combine diacritics-insensitive, case-insensitive and partial search in MongoDB?
I'm trying to implement a robust search function in my NestJS/Mongoose application that can handle partial matches while being case-insensitive and diacritics-insensitive (ignoring accents).
My ...
0
votes
0
answers
24
views
Connect node app running in docker to mongodb running in another container [duplicate]
I've a docker-compose, that declares 2 services, a mongo bd and a python scripts. If I run this docker compose up it works fine.
services:
mongo:
image: mongo:7.0
container_name: mongo_db
...
0
votes
2
answers
58
views
How to correctly type $and operator in MongoDB TypeScript driver without double WithId nesting?
I'm building a strongly-typed generic MongoDB repository in TypeScript (using the official mongodb driver, v6.x).
I want to compose filters dynamically using $and, but the TypeScript type system keeps ...
0
votes
0
answers
28
views
$vectorSearch pre filter by non existent properties
When using the $vectorSearch aggregation stage and specifying filter, using the $exists operator isn't supported, but another way of effectively doing the same thing is to check if the property value ...
0
votes
1
answer
60
views
Spark 4.0.1 MongoDB Connector 10.5.0: Missing configuration for: collection and NoClassDefFoundError: com.mongodb.client.MongoClient
I am trying to read data from MongoDB in Spark 4.0.1 using the MongoDB Spark Connector (version 10.5.0). My PySpark code looks like this:
from pyspark.sql import SparkSession
spark = SparkSession....
Best practices
1
vote
0
replies
33
views
Kotlin Serializer: Different SerialName per Serializers id/_id
Using the "MongoDB Kotlin Driver" is there any best practices to define the data model? Particularly regarding the _id vs id while sharing the same data model to serialize through different ...
0
votes
1
answer
105
views
How can I clone objects without retrieving them in MongoDb?
I use MongoDb in C#. Shown below is an object I want to clone, but also I want to merge it into the same collection.
This is a simplified version of the document I use:
class MyDocument
{
public ...
3
votes
1
answer
58
views
Query not printed as expected
exports.getAllProducts = async (req, res) => {
try {
console.log(req.query);
const queryObj = { ...req.query };
const excludedFilters = ["page", "limit", "...
3
votes
2
answers
118
views
MongoDB $regexMatch error: "needs 'input' to be of type string"
I'm getting an error in my mongodb aggregation pipeline with the $regexMatch operator. I'm trying to match fields that contain ISO date strings and convert them to a different format.
Here's the ...
0
votes
1
answer
57
views
Custom error objects for Mongoose schema paths
Take the following Mongoose schema.
const userSchema = mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
minLength: 3
},
name: ...
3
votes
1
answer
92
views
Django Mongodb Backend not creating collections and indexes
Summary
Running Django migrations against our MongoDB database does not create MongoDB collections or indexes as defined in our app. The command completes without errors, but no collections or indexes ...
0
votes
0
answers
74
views
mikro-orm - reading entity data by given reference IDs
I'm kind of new to mikro-orm, trying to wrap my head around as how to correctly define
the relations between some of my entties in my collections.
The idea is to store all my pre-defined modules in ...
0
votes
0
answers
74
views
How to overwrite an env value with Helm
I want to deploy an app on Kubernetes with Helm. This app is composed of multiple parts, 2 of them are a Spring backend and a Mongo database.
I want to deploy theme in 2 pods and have them talk with ...
0
votes
0
answers
54
views
Mongock rollback method is not executed
I have a collection migrationTest in MongoDB with a unique index for the message field.
In my migration I'm inserting documents to this collection and in one place I'm using the existing message to ...
0
votes
1
answer
116
views
Randomly slow MongoDB queries
I have been experiencing slow mongo queries suddenly. The execution times varies very randomly. Initially I was suspecting this expensive aggregation operation :-
{
"appName": "XXXXXX&...
4
votes
2
answers
90
views
Is MongoDB BSON Timestamp signed or unsigned?
The BSON Timestamp type, documented here https://www.mongodb.com/docs/manual/reference/bson-types/, includes a 32-bit time_t field. Does anyone know whether this field is signed or unsigned? If signed,...
1
vote
2
answers
57
views
Laravel + MongoDB: Update nested value in Model
I have Model with a deeply nested attribute:
$model = Model::create();
$model->nested_prop = ['foo' => ['bar' => ['x' => 1]]];
$model->save();
In another method I want to modify a ...
3
votes
2
answers
149
views
MongoDB Go driver’s topology view is stale and reports no primary indefinitely
I'm encountering an issue in a Go application that uses the official MongoDB Go driver. We have the use case where a ReplicaSet is recreated from scratch. Replica Set consists of 2 members, no arbiter ...
3
votes
0
answers
104
views
Azure Cosmos: MongoDB sharded cluster: $in query performance degrades with fewer values
I'm facing a counter-intuitive performance issue with my MongoDB sharded cluster where queries with fewer values in an $in clause are significantly slower than queries with more values.
The Issue:
...
2
votes
1
answer
80
views
Should I close the DB connection in NextJS
I am new to programming (and NextJS) and I'm building a NextJS app, using Mongoose for my MongoDb connection. I was wondering if I should close the connection after each query? Right now I am just ...
0
votes
0
answers
62
views
After upgrading mongodb to v5+ getting a "com.mongodb.MongoTimeoutException: Timed out.." in spring boot tests
Disclaimer: There are a couple of questions for this exact exception, sadly none of those match my environment or circumstances (thus i think this question is unique)
In my case i have a:
working ...
0
votes
0
answers
69
views
NestJS converting mongodb snake case to camel case format but it returns undefined
I'm currently trying to create the model using nestjs mongoose schema, and i want to convert the mongodb data from snake case to camel case in my schema layer like this:
export type ...
0
votes
1
answer
59
views
How to create a custom replication guarantee?
I have 4 members in my replica set:
{
_id: 'mdbDefGuide',
version: 16,
term: 63,
members: [
{
_id: 2,
host: 'localhost:27019',
arbiterOnly: false,
buildIndexes: ...
0
votes
1
answer
53
views
Mongo unexpected mongo queries
i have some problems in production using mongo
We have python using mongo and mongo-express for ui. And we are facing performance issues, after research i found db.currentOp() to see queries which are ...
0
votes
2
answers
75
views
Can a partial multikey index in MongoDB index only certain subdocuments of an array?
I have a MongoDB collection with documents containing an array of subdocuments. For example:
{
"_id": 1,
"addresses": [
{ "city": "New York", "...
1
vote
0
answers
47
views
Watching for changes on an array of a document in a Mongo collection only triggers on the second push, not the first
Say I have a document in a Mongo collection that looks like the following:
{
"_id": "01:550204",
"somefield1": "someValue1",
"somefield2": "...
0
votes
2
answers
180
views
How can I update my server file so that I can have the server up and running?
I am running my backend using mongodb and express. I am restarting the server using nodemon. After running:
npm run dev
I am getting the error below:
> [email protected] dev
> nodemon server.js
[...