46,593 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
Score of 0
2 answers
67 views
$elemMatch does not apply the "AND" operator when querying data in MongoDB
I have designed a Product schema based on the Attribute Pattern. The aim is to allow users to query data using different parameters.
Product Schema:
const AttributeSchema = new Schema({
k: { type: ...
- reputation score 171
Best practices
0
votes
0
replies
68
views
Best practice for using GridFS with NestJS + Mongoose — should I still use native MongoDB GridFSBucket?
I am migrating a NestJS backend from TypeORM + native MongoDB usage to Mongoose.
Most collections have already been migrated successfully using @nestjs/mongoose and InjectModel.
However, I still have ...
Score of 0
0 answers
123 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:...
Score of 0
0 answers
135 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 ...
- reputation score 19
Score of 1
2 answers
75 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 ...
- reputation score 11
Score of 1
1 answer
85 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 ...
- reputation score 39
Score of 1
2 answers
74 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&...
Score of -1
2 answers
88 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 ...
- reputation score 8
Score of 0
1 answer
133 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 ...
Score of 1
1 answer
82 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 ...
- reputation score 13
Score of 2
2 answers
106 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 ...
Score of 2
1 answer
2175 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 ...
- reputation score 71
Score of 5
1 answer
1699 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
...
Score of 0
0 answers
49 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 ...
- reputation score 178
Score of 3
0 answers
84 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 ...
- reputation score 964