Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
32 views

Error handling in NodeJS service classes and controllers

I am very new to both JavaScript and NodeJS and am struggling to grapple some of the concepts surrounding async, promises, and others, and especially how to structure the code properly. I am trying to ...
heradsinn's user avatar
  • 113
1 vote
1 answer
38 views

is it possible to check whether the user-given foreignFieldId (req.body.foreignFieldId ) exists or not before calling db.create(req.body) in MongoDB

Product Schema: const productSchema = new mongoose.Schema({ name: { type: String, required: true }, price: { type: Number, required: true }, addedBy: { type: mongoose.Types.ObjectId, ref: '...
Avijit Sengupta's user avatar
0 votes
1 answer
79 views

a confusion about schema design for storing store's profits and how to retrieve them in mongoose [closed]

For displaying the (daily-weekly-monthly-annual) total profits for the store's dashboard. I want to store the data in an array for each store to not have multiple docs for the same store but different ...
Marya's user avatar
  • 170
0 votes
1 answer
49 views

How can I properly handle database connections in a Node.js application?

I'm building a Node.js application using Express.js and MongoDB (Mongoose). I want to ensure that my database connections are handled efficiently to avoid memory leaks and connection issues. Currently,...
CodebergIT Technology Works's user avatar
-2 votes
1 answer
49 views

Is Mongoose really an ORM, or is it something else? [duplicate]

I keep hearing people say that Mongoose is an ORM for MongoDB, but I thought ORMs are for relational databases like MySQL or PostgreSQL. Since MongoDB doesn’t use tables and rows but instead works ...
Rao Imtinan's user avatar
0 votes
2 answers
67 views

POST document hook or middleware in mongoose isn't working

I'm using mongoose v8.7.3, here is part of my code which is not working as expected. const updateOne = (Model) => catchAsync(async (req, res, next) => { const doc = await Model....
M_T's user avatar
  • 33
-1 votes
0 answers
40 views

Securely Updating User's Password / NodeJs - Mongoose

I am trying to create a secure password reseting system by using JWT. While doing pass reset, i was trying to use mongoose. At first i tried to update my user, only using updateOne() mongoose function....
silenceofworld's user avatar
0 votes
1 answer
44 views

Node.js script hangs after saving documents to MongoDB with Mongoose, despite successful document saves

I have a Node.js script that uses Puppeteer to scrape job vacancy IDs from a website and Mongoose to save those IDs to a MongoDB database. Each vacancy is saved correctly, but the script hangs after ...
Emiliano's user avatar
0 votes
1 answer
70 views

Find by array of Ids not working with Mongoose aggregate method

I would like to use the aggregate in mongoose to get documents that match the ids in the array. The array contains mongoose object ids. It is returning an empty array. Here is my code: let ...
superkingz's user avatar
0 votes
1 answer
40 views

Mongoose - How to read findOneAndUpdate result when includeResultMetadata flag is set?

I am using mongoose findOneAndUpdate (reference) query function with includeResultMetadata and lean flags set. It responds with object of type ModifyResult (reference) which looks like: { ...
rajan_saini.98's user avatar
5 votes
2 answers
227 views

Share mongoose connection between repositories in a TypeScript monorepo

My MonoRepo structure Full example and testable code is here: https://gist.github.com/SohamRoyNoel/c50fac02c0f07d3816e8f31797478013 Intent: I want to bring out database from app1 and app2 level and ...
Nick's user avatar
  • 321
0 votes
1 answer
51 views

Can't display user data from database

I want to get data from database and display it in html code through <%= %> tag. // index.js const express = require('express'); const router = express.Router(); const { ensureAuthenticated } = ...
Stefan's user avatar
  • 1
0 votes
0 answers
15 views

interface for model and general in ts

I am stuck in a situation please help. I created a interface for User Model in mongoose and ts. the model has profile pic field which consists of a reference to document model. so my user schema model ...
Brahm Bind Singh's user avatar
0 votes
1 answer
28 views

How to add a required value with a middleware?

I want to make the generation of the codigoSS before the validation but when i try the end point i recibe the message: "Solicitud validation failed: codigoSS: Path codigoSS is required.". ...
Giovanni Palencia's user avatar
-1 votes
0 answers
52 views

Problems with displaying pictures on EJS Form with NodeJS

My problem is related to displaying images from a MongoDB database (I use mongoose) on a page made with EJS. I save the object to the database absolutely correctly, but when I try to display it on the ...
Black Woron's user avatar
2 votes
1 answer
51 views

How do I clear all indexes in a newly instantiated reused Schema?

I'm developing a Mongoose plugin that archives documents on every update by cloning the original schema. However, I'm facing an issue with unique fields: when a field is marked as unique, Mongoose ...
Eiskaffee's user avatar
1 vote
1 answer
40 views

pull method not available for mongoose.Schema.Types.ObjectId[]

Hey I have created a model User like so: import mongoose from 'mongoose'; const Schema = mongoose.Schema; const userSchema = new Schema( { email: { type: String, required: true, ...
Mr.Unforgettable's user avatar
0 votes
1 answer
70 views

How to initialise the data containing certain images?

i am getting Cast to string failed for value error see here the code to initalised that data const initDB = async ()=>{ await Listing.deleteMany({}) ; await Listing.insertMany(initData.data)...
Darshan's user avatar
1 vote
1 answer
28 views

MongoServerError: 'timestamp_property' must be present and contain a valid BSON UTC datetime value

I'm encountering the following error when trying to post sensor data to my API: MongoServerError: 'timestamp_property' must be present and contain a valid BSON UTC datetime value. Here's the code for ...
Bob's user avatar
  • 11
0 votes
1 answer
41 views

Mongoose replica set with docker

I spend whole day trying to figure out how can I convert my standalone mongod to Replica Set I and have failed. This is how I'm doing it without replication. docker-compose.yaml volumes: mongo....
Majkon's user avatar
  • 71
0 votes
2 answers
102 views

Can't connect to my mongdb database using mongoose (nodejs)

Im trying to connect to my database. Its working if i use mongodb compass but then im using mongoose to connect it doesn't work. I keep getting this error: Mongoose connection error ...
Gerardo Acedo's user avatar
0 votes
0 answers
35 views

How to enforce type safety when updating a Mongoose document in TypeScript?

I'm working with a Mongoose model in TypeScript, and I'm experiencing unexpected type behavior during document updates. Code Context // Game model definition import mongoose, { Model, model, Schema } ...
studio-pj's user avatar
  • 874
-1 votes
1 answer
25 views

Possible to export an async function from a Mongoose.js model to simulate findOne() with callback

I recently updated a large project to the newest version of Mongoose and realized that support for callbacks in findOne() have been dropped. I'm curious if anyone has recommendations for the most low-...
Chris's user avatar
  • 57
0 votes
0 answers
158 views

Error deploying Node.js API on Render, 'MODULE_NOT_FOUND'

I am uploading my simple node.js project to render. It is a simply API that runs great locally, but I get the following error when I upload. - /opt/render/project/src/node_modules/mongoose/lib/index....
Yisroel Arnson's user avatar
0 votes
1 answer
36 views

Argument of type 'import("mongoose").Types.ObjectId' is not assignable to parameter of type 'import("mongoose").Schema.Types.ObjectId'

Argument of type 'import("mongoose").Types.ObjectId' is not assignable to parameter of type 'import("mongoose").Schema.Types.ObjectId'. Type 'ObjectId' is missing the following ...
Aswanth's user avatar
0 votes
0 answers
40 views

MongoDB populate sporadically not working for same dataset

I am facing this issue where I have appointments and customers and contacts and while getting an appointment I am using populate to populate the customer from appointment, The issue is it has been ...
Seerat Ahmed's user avatar
1 vote
0 answers
62 views

Why am I getting the error Cannot read properties of undefined (reading 'findOne') when trying to add an address to a user?

I'm working with a Node.js application using MongoDB and Mongoose, and I have two models: User and Address. I am trying to add an address to a user, but when I try to call findOne on the Address model,...
Maa Henna Art by Sakshee's user avatar
0 votes
1 answer
40 views

Getting Validation Failed: Path is required Error even when I am providing all the required data

I am using Mongoose in my Nodejs application and I want to create a new Experience collection. For that I am providing all the data in Postman. I am using application/x-www-form-urlencoded to send my ...
Revolter23's user avatar
1 vote
1 answer
33 views

A declared function is not working in login route in express.js

I'm working on a project where I'm creating the login and registration functions of the website. Registration is working but in the login section, the given password and the password stored in the ...
Tejashv's user avatar
  • 13
0 votes
0 answers
23 views

How to create unique fields in MongoDB with Mongoose?

I am working on a Node.js project and using MongoDB with Mongoose (version -8.9.2). I want to enforce uniqueness for certain fields in my database (e.g., email) to ensure no duplicates are allowed. ...
Nuwan Madusanka's user avatar
0 votes
0 answers
45 views

mongodb and nextjs connetion problem GET http://localhost:3000/api/movies 404

i created a cluster in mongodb atlas it had some dummy data like this "sample_mflix(movies(title, runtime, year))" and i want to display it on a table, here is the code for the component ...
paramicia's user avatar
0 votes
0 answers
34 views

Filter records by subdocument array

I am using findOne() to filter record base on the field of the nested subdocument but findOne() and find() are returning all the records instead of filtering it by the subdocument field. WHAT I WANT ...
Raul Hernandez's user avatar
-1 votes
1 answer
95 views

Strange : MongoDB Connection Failed: connect ECONNREFUSED ::1:27017 [duplicate]

I have already gone through all the solutions provided for this issue and attempted to resolve it. However, everything seems to be working fine on my PC—MongoDB services are running without issues, ...
Monu Rohilla's user avatar
0 votes
1 answer
92 views

How can I solve the Mongodb atlas connection error in nodejs?

I'm getting below error while try to connect mongodb atlas database with nodejs mongoose: Error: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying ...
sugnay patel's user avatar
1 vote
1 answer
56 views

How to Apply JS Mongoose Aggregate Regex Match to String Array and Other Fields

I am trying to write an aggregation to regex match a search string across various fields in a list of items. Here is an example JSON array of those items: { "user": "String", ...
Sniper Noob's user avatar
0 votes
0 answers
72 views

Can't connect to MongoDB atlas using Mongoose 8.9.1

My MongoDB URI looks like this mongodb+srv://<db_admin>:<db_password>@maincluster.expmq.mongodb.net/<db_name>?retryWrites=true&w=majority&appName=MainCluster I have a ...
Rizul Bhardwaj's user avatar
0 votes
1 answer
53 views

NodeJs Application memory usage is increasing

I created Application with multitenant structure using nodejs, expressjs and mongoose when I start the application the memory usage for its process it normal but with time few hours and usage few ...
Mohamed Maher's user avatar
0 votes
0 answers
36 views

(aggregate) Intersection between values in an array of maps node js mongoose

What i'm trying to do is to find all values of key1 common in doc1 and doc2. I have a collection called Signups with two documents doc1 & doc2 Signups : { _id : String, links : [ { ...
alaa's user avatar
  • 73
0 votes
0 answers
14 views

This is Error of duplication of subCategory

This is Error of duplication of subCategory { "message": "Failed to create subcategory", "error": "E11000 duplicate key error collection: shoesEcom.subcategories ...
Dhruv Kachwala's user avatar
0 votes
0 answers
74 views

I am building a YouTube Shorts clone using Next.js and Swiper but have encountered several issues

Videos are stored on firestorage and a mongo database. Link Transition Issue: When the user clicks on a video link, the video is displayed as the first item in the slider. However, when scrolling to ...
John Red's user avatar
1 vote
1 answer
63 views

TypeScript Error in Express Route: "No Overload Matches This Call" [duplicate]

Question: I am developing an e-commerce platform using TypeScript with Express. Below is the code snippet and the error I am facing. How can I fix this issue, and why does the solution work? Code ...
Harshal Malani's user avatar
0 votes
0 answers
30 views

Changestream for mongodb insert operation

Actually i want to use changeStream for my chat application to write on insert operation changeStream.on('change', (change) => { if (change.operationType === 'insert') { res....
web devlopment king's user avatar
0 votes
0 answers
24 views

Mongoose populate() not working as expected, returning ObjectId instead of the full object

I'm using Mongoose in my Node.js application. I have a Booking schema that references a Place schema using ObjectId. When I use the populate() method to retrieve the Place object, it only returns the ...
Atharv Gupta's user avatar
1 vote
1 answer
30 views

The right way to create safe transactions in MongoDB

I’m working on a Node.js application using Mongoose and MongoDB. In the following code, I’m using a transaction to handle creating a new topic with an automatically incremented position. My goal is to ...
Alex's user avatar
  • 11
-1 votes
1 answer
34 views

About automatically deleting data in mongodb

I am adding some data into mongodb. However, the data is automatically deleted after a certain period of time. I do not want this data to be lost or deleted const mongoose = require('mongoose'); const ...
Sakulta Salkım's user avatar
0 votes
0 answers
32 views

Mongoose in serverless - why awaiting connection helps to avoid duplications?

I'm fairly new to serverless development and trying to find the best practice for using mongoose in such environment. A page in official documentation (Using Mongoose With AWS Lambda) explains the way ...
algConf's user avatar
0 votes
0 answers
25 views

Specifying $and logic in a CASL rule

I understand from the CASL docs that logic operators like $and, $or etc. have not been implemented in CASL for mongoose $or can easily be specified by separate can rules with the same action and ...
devnull69's user avatar
  • 16.6k
1 vote
1 answer
33 views

Postman POST call works Angular doesn't [duplicate]

I have the following problem: I am trying to make a mew record in a mongoDB database using a call from an Angular frontend. For some reason when i initiate the POST request i dont get any kind of ...
Callistron's user avatar
1 vote
1 answer
47 views

Type autocompletion for populated mongoose document

I am using mongoose with Nextjs. If you look at the Review Schema below. It is linked with User schema and I am using the Review schema with populate in my React page to get the User document data, i-...
kazmi066's user avatar
  • 625
0 votes
1 answer
24 views

node js/mongodb: Update document while looping object/array

I want to loop an array, and for every instance, find a document from mongodb, do some task, and increment the document's value. But I only got the document incremented once. (That's my problem); ...
Jalagui's user avatar
  • 35

1
2 3 4 5
646