46,657 questions
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 ...
3
votes
1
answer
59
views
Query not printed as expected
exports.getAllProducts = async (req, res) => {
try {
console.log(req.query);
const queryObj = { ...req.query };
const excludedFilters = ["page", "limit", "...
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: ...
0
votes
0
answers
16
views
Mongoose Virtual Not Populating in MERN Stack Despite Correct Schema Setup
//User Schema
const userSchema = new mongoose.Schema({
name: String,
email: String
});
userSchema.virtual('posts', {
ref: 'Post',
localField: '_id',
foreignField: 'author'
});
//Controller
...
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
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
0
answers
22
views
findByIdAndUpdate doesn't work with discriminators
I have these two schemas with discriminator. It's custom activity that also has fill in the gaps questions which is another schema. For some reason when I use findByIdAndUpdate, it updates all the ...
0
votes
1
answer
67
views
MongoDB query with Mongoose - Matching subdocument attribute within an array
I am trying to solve an issue with the format of documents in a MongoDB depicted below.
{
"_id": {
"$oid": "68dc4f78e11553b3647231e2"
},
"name": "...
0
votes
1
answer
42
views
Using mongoose discriminator in an Nextjs app throws OverwriteModelError even if the cached value is used
While defining the model, discriminators are created on the basis of the SchemaVersion. On export, the already created discriminator model is returned to prevent the overwrite errors from mongoose ...
0
votes
1
answer
54
views
MongoDB - Cannot get nested document by _id
When I execute the following code in my application:
const freelancer = await Freelancer.findOne(
{ _id, 'experiences.title': 'Frontend Javascript developer' },
{ 'experiences.$': 1 }
);
console....
0
votes
0
answers
69
views
ValidationError: MyModelSchema validation failed: items.0: Cannot read properties of undefined (reading 'model')
I am working on migrating the project to a new version. Stack: express 5, mongoose 8, typescript 5.8, typegoose 12
I looked for more information and would now like to clarify the cause of the problem:...
0
votes
0
answers
72
views
Mongodb $push $each onto array is resetting createdAt date for all subdocuments
Hopefully this makes sense. Using mongoose to push new items into an array of subdocuments, the documents get added fine, however on certain (random) occasions, the createdAt date of the current ...
2
votes
1
answer
99
views
How to use a virtual property based on foreign data in nestjs/mongoose?
I would like to know how to use @Virtual from nestjs/mongoose to calculate a local field with fields from another schema (like a classic mongoose populate)?
I have this InvoiceHub schema that ...
0
votes
1
answer
50
views
Mongoose - unknown operator: $text
I have a mongoose schema where I defined a text index like this:
FreelancerSchema.index({ title: 'text', presentationText: 'text' }, { weights: { title: 2, presentationText: 1 } });
I try to search ...
2
votes
0
answers
137
views
MongoDB Atlas connection error: queryTxt ETIMEOUT with Mongoose
Mongoose connection to MongoDB Atlas fails with queryTxt ETIMEOUT
I’m trying to connect my Node.js app to MongoDB Atlas using Mongoose, but the connection fails with a timeout error.
Here’s the error ...
1
vote
0
answers
46
views
MongoDB/Mongoose: Calculating large time series differentials in Node.js is too slow (~5–6 seconds) despite indexing and $slice
I’m building a financial backend in Node.js/Express that serves bond yield differentials for two countries at minute granularity.
Each country+bond maturity pair is stored in MongoDB as a single ...
0
votes
0
answers
114
views
Trying to pass UserID to API through form. The ID is retrieved, but doesn't seem to be passed
I'm making an event management application. I'm using better-auth & mongodb. I got a form in which I can create an event. Now, alongside the event name, and dates I want to pass along the owner's ...
0
votes
0
answers
79
views
Getting error in deploying on render and error in node_module how can i fix it?
I'm deploying a Node.js backend using Mongoose, and I'm getting the following error during build on Vercel:
Error: Cannot find module './bulkWriteResult'
Require stack:
- /vercel/path0/backend/...
1
vote
1
answer
54
views
Date range filter returns incorrect results in MongoDB query
I'm implementing a date filter feature that allows users to filter results using from and to date parameters. The filtering works correctly for some date ranges but returns unexpected/incorrect data ...
2
votes
3
answers
105
views
Why is statusUpdatedTime undefined in my Node.js/MongoDB app?
I’m working on a Node.js app with MongoDB (using Mongoose), and I’m trying to set or update a statusUpdatedTime field in a document. But when I check the document after the update, the field is either ...
0
votes
0
answers
83
views
Mongoose Document array not updating
I seem to be unable to access or update an array in a document using mongoose. here's my setup:
type DemoSchema = {
strings: string[]
}
const DemoSchema = new Schema<DemoSchema>({
...
0
votes
1
answer
58
views
Mongoose throws error when saving with an invalid key, but not when updating
I use MongoDB for my database and use {strict: "throw"} to throw an error with invalid data. When I save a new instance with a field that is missing from the schema, I get an error. But when ...
1
vote
1
answer
53
views
Mongoose: What is the best way to validate updators using multiple fields upon calling `findOneAndUpdate`?
I have a Mongoose schema with NestJS:
@Schema({
versionKey: false,
id: false,
collection: "basics",
timestamps: false,
toJSON: {
virtuals: true,
},
toObject: {
virtuals:...
0
votes
1
answer
77
views
Save a user in an array in a POST request
I'm new to back-end development. I'm doing the FCC back-end challenge, and I'm having a problem because they're asking me to return an array in a GET request that contains all the existing users. But ...
0
votes
1
answer
59
views
MongoDB Operation Timeout Error: products.find() buffering timed out after 10000ms
MongoDB Operation Timeout Error: products.find() buffering timed out after 10000ms
Problem
I'm getting a timeout error when trying to fetch products from my MongoDB database using Mongoose in my ...
2
votes
1
answer
42
views
MongoDB document not persisting modified subdocument changes
I'm running into a strange issue when updating a Mongoose document.
I'm trying to update a field (paymentType) inside an array of subdocuments (students) in a Teacher document. Both console.log(...
0
votes
0
answers
43
views
Dynamic route on nextjs deployed on vercel not working
I was working on Nextjs BLOG project, built api's then deployed it in Vercel post, get all, and delete seem to work. But get indivisual post to view and put method for editing don't work, (dynamic ...
1
vote
0
answers
56
views
Mongoose: How to customize the CastError message for invalid
I want to override the default Mongoose cast error message when a value is not a string.
I have a field firstName defined like this:
@Prop({
type: String,
required: [true, 'firstName is required'],...
0
votes
1
answer
69
views
How to define what type of value .toJSON() returns when called on a Mongoose Document?
I am trying to define a toJSON function in my schema so that it will remove __v and replace _id as id and remove pwd from the document as well when .toJSON is called.
import { model, Schema } from &...
-1
votes
1
answer
80
views
Node.js server not logging anything when I run server.js
I'm building a MERN stack app and trying to start my backend server using Node.js. I run:
node Backend/server.js
But nothing happens ,there's no output in the terminal at all (no success messages, no ...
0
votes
1
answer
78
views
How can I authenticate after migrating to Mongoose 8?
I am trying to upgrade my express code from using Mongoose version 5.13.7 to 8.15.1 and I am not able to authenticate to my Mongo database anymore.
The code that used to work:
mongoose.connect("...
1
vote
0
answers
64
views
Buffering timed out after 10000ms
Whenever I run this JS using Node, I first get a console.log() back saying the database is connected. However, I get an error message afterwards saying:
MongooseError: Operation campgrounds....
0
votes
0
answers
70
views
Possible to add default class to a mongoose Schema?
A of class="active" is added based on what star I click on. With schema, how do I connect it to the db, creating a default 1 star to every post? Tried to do it with "score:" but ...
0
votes
1
answer
85
views
Data undefined in Vercel NextJS production with Mongoose
So I have some models in my MongoDB database, which details I am trying to fetch via Mongoose in NextJS, everything works in development but in production the data is not being fetched. I have been ...
0
votes
0
answers
18
views
req.query remains empty even after attempting to add a property in Express middleware [duplicate]
Body:
I'm working with Express.js, and I'm trying to add a status property to req.query in middleware, but it remains empty. Here’s my code:
Route:
router.get(
"/published",
faqController....
1
vote
1
answer
41
views
mongo db from on model to another model
I'm using Mongo DB for my database and I'm using mongoose for managing it in my backend code.
I have 3 models in this details.
the first model is Media for getting files form users.
the second is ...
0
votes
0
answers
738
views
Betterauth and Mongodb/mongoose
I am trying to implement better auth for user signin and signout in nextjs as well as expo router.
I keep running in the error: ERROR [Better Auth]: User not found. Other tutorials I have seen online ...
0
votes
0
answers
78
views
Mongo DB - retry once it failed to connect
I am using mongoose to connect db in express, While in production app is running on, sometimes in the time of performing query on db mongoose unable to connect database and through connection timedout ...
0
votes
1
answer
64
views
Querying by _id ObjectId returns an empty array using Mongoose
I have the following function:
export const findCustomer = async (query?: FindCustomerParams) => {
try {
await database.connect();
} catch (err: any) {
throw new Error("Could not ...
1
vote
0
answers
60
views
Mongoose .populate() returns field in result but accessing it gives undefined unless added to schema
I'm working on a Mongoose setup where I have an Employee schema that includes fields like name, employeeId, departmentId, and designationId.
Recently, I manually added a new field photo to a document ...
0
votes
0
answers
42
views
Mongoose populate plugin with Typescript
I've been trying to create a plugin which implements a query and schema method that populates a user field and selects some inner fields from it (firstName, lastName, image).
I just can't seem to make ...
3
votes
0
answers
60
views
how TypeScript types + Mongoose typings behave, and why certain return types “just work” while others don’t
I'm new to express and I'm using Mongoose with TypeScript and ran into a typing inconsistency that I can't wrap my head around.
I have a custom interface IVoyageLeg that extends Document, and I'm ...
0
votes
2
answers
60
views
auth mechnism failing in mongodb
while starting from mongod.conf using below entry mongod not running throwing error:
mongod.service : main process exited, code=exited, status=2/INVALIDARGUMENT
IN MONGD.CONF: when commenting ...
1
vote
0
answers
59
views
How to create generic types in a mongoose schema
I'm trying to create a nest Schema for mongoose that uses typescript's generic types.
The goal here is to restrict my database with a few types (everything will be validated with Joi or equivalent, ...
0
votes
0
answers
50
views
how to check if the document id isn't wrong in case of dynamically created models/collections?
I want to create a middleware function to check if the document_Id exists and it's not wrong using Model.exist({_id: id}) or such a query, so the API throws an error.
However, the problem is my models/...
0
votes
0
answers
70
views
Command Return; "The application did not respond", but there was no error detected
config-suggestion.js
const { SlashCommandBuilder, ChatInputCommandInteraction, ChannelType } = require('discord.js');
const GuildConfiguration = require('../../models/GuildConfiguration');
module....
2
votes
1
answer
196
views
Mongodb & mongoose :: Cannot call create() with a session and multiple documents unless ordered: true is set
I’m using [email protected] with [email protected]. I’m trying to use the create() method in Mongoose along with a session for transaction support. However, when I try to insert multiple documents, I get ...
0
votes
0
answers
44
views
Reupdate the database will not roll back the previous database state
I've got this code for updating the match which will also update the other 3 models player team and tournament
the code goes like this
const updateMatch = async (req, res) => {
try {
const { ...
1
vote
2
answers
99
views
Mongoose update nested data without erase other data
I inserted a client in my "clients" collection.
data inserted
{
"type": "private",
"name": "Client 1",
"contact": {
&...
0
votes
1
answer
72
views
NextJs mongodb: App deployed to Vercel connects too many times to the database
I have a NextJs app built with mongodb database.
I was surprised to see that I quickly almost reached the threshhold of maximum connections:
This app used to be built with node and react and this was ...