46,613 questions
0
votes
0
answers
76
views
MongoDB Node driver heartbeat fails on replica set advertised host in Docker, while direct container connection is stable
I have a Node.js application using Mongoose against a single-node MongoDB replica set running in Docker.
Environment:
My application connects with a seed URI like this:
const dbURI = `mongodb://user:...
0
votes
0
answers
107
views
MongoDB Atlas connection error in Node.js: querySrv ECONNREFUSED _mongodb._tcp.cluster0
I am building a MERN application and trying to connect my Node.js backend to MongoDB Atlas using Mongoose.
However, when I start my server, I get the following error:
Error: querySrv ECONNREFUSED ...
1
vote
2
answers
69
views
$match does not match all the fields entered
I am facing an issue with a MongoDB aggregation pipeline that uses the $lookup operator. The goal is to create a pipeline that filters data in my database based on input fields and returns the ...
1
vote
1
answer
73
views
TypeScript error when caching mongoose connection globally — Promise not assignable
I am trying to create a reusable MongoDB connection function using Mongoose in a Node.js / Next.js project with TypeScript.
To prevent multiple connections during hot reload, I am caching the ...
1
vote
2
answers
67
views
MongoDB Atlas Search Index Query Required
I have this search index in my Atlas Cloud DB:
` { "mappings":
{ "dynamic": false,
"fields":
"email": [ { "maxGrams": 12, "minGrams&...
-1
votes
2
answers
83
views
Mongoose & TypeScript
TypeScript this Error in Mongoose Static Method with timestamps + Virtual Populate
Question
I am using Mongoose 9.2.2 with TypeScript 5.9.3, and I have a schema that includes:
timestamps: true
a ...
0
votes
1
answer
93
views
Mongoose querySrv ECONNREFUSED with Node v22.22.0 on Windows - Works on Render but fails locally
I'm facing a persistent connection issue with Mongoose and MongoDB Atlas ever since I updated/reinstalled Node.js to version v22.22.0. Interestingly, the exact same code works perfectly when deployed ...
1
vote
1
answer
76
views
Mongoose seems to be ignoring CSFLE options
I'm working on an AWS Lambda that needs to encrypt some data going to Mongo Atlas via CSFLE. I have logic in place that creates and saves the DEK to Atlas no problem, but when I use Mongoose to ...
2
votes
2
answers
98
views
Query deeply nested document with dynamic key
I want to return a specific subdocument which is nested in a second level array.
My problems are:
The document is deeply nested
The fields (keys) are dynamic and based on req.body values
The ...
2
votes
1
answer
1k
views
MongoDb Connection failed : Error: querySrv ECONNREFUSED
MongoDb Connection failed : Error: querySrv ECONNREFUSED
How can I solve this error? My node v24.13.0 and mongoose 9.1.5 are the latest versions. Also I changed my network dns to Google's dns number ...
5
votes
1
answer
1k
views
MongoDB Atlas SRV connection fails with querySrv ECONNREFUSED after switching Node versions (Node 22, Windows)
I’m running into a MongoDB connection issue that only appeared after switching Node.js versions, and I haven’t been able to resolve it despite extensive troubleshooting.
Environment
OS: Windows 10
...
0
votes
0
answers
46
views
Property [bsonType] is missing in typescript interface, when trying to generate mongoose compatible in typescript
I'm trying to generate a compatible type for Mongoose/bson ObjectId for a part of my repo which holds types which is shared between my Frontend and my Backend.
I don't want to install/load mongoose or ...
3
votes
0
answers
80
views
How to check if a document is mongoose sub schema in middleware?
I am building a multi-tenant application, and I am using a global plugin instead of adding a plugin to each model one by one. This plugin will handle adding organizationId during filters, saving, and ...
3
votes
1
answer
68
views
Why is Promise.all not supported inside MongoDB (Mongoose) transactions?
I’m using MongoDB transactions with Mongoose, and I noticed a warning in the official docs that confused me regarding concurrency.
According to docs for ClientSession.startTransaction():
IMPORTANT: ...
1
vote
1
answer
139
views
Error when implementing auto-increment functionality using 'mongoose-sequence': "TypeError: next is not a function."
I am having trouble with the implementation of the mongoose-sequence library in my MongoDB, Express, Node.js API.
This project is one for adding people to a database. Each person has a firstName, ...