Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
0 answers
38 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/...
Marya's user avatar
  • 172
2 votes
1 answer
52 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 ...
Leo_code's user avatar
0 votes
0 answers
35 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 { ...
Santosh Jugjali's user avatar
-1 votes
0 answers
48 views

MongoDB Difficult Query

there. I have some documents in my mongodb database. The structure is: _id: MongodbId, colorId: MongodbId, isParentProduct: boolean parentProductId: MongodbId [ { "_id&...
Mike's user avatar
  • 421
1 vote
2 answers
70 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": { &...
Steeven Delucis's user avatar
0 votes
1 answer
49 views

Issue with Tree Structure MongoDB

I'm using MongoDB with Nodes js and Mongoose, and I'm creating a hierarchical tree structure. In each collection, I have a document with the ID of that document, an entry with the parent ID as ...
Juliette Mylle's user avatar
0 votes
0 answers
25 views

GraphQL MongoDB data null output in createUser

I'm having a trouble on how to create a simple CRUD with GraphQL + MongoDB first start with the creating a user. In my postman, I type this in GraphQL Query mutation CreateUser($username: String!, $...
Myth Vince's user avatar
0 votes
1 answer
37 views

how can the index for a field in a document in a mongo database be updated to reflect the changes I made in the mongoose schema?

if my schema looks like this: const schema = new mongoose.Schema({ username: { type: String, }, password: String, }); and I want to add "unique: true" to the schema. the relevant ...
لوسيفر جبريل's user avatar
0 votes
2 answers
73 views

How to get the query from the then function?

I'm using a Mongoose query like this: let Value = 'START' myCollection.findOne({param:Value}) .then((doc) => { if (!doc) { // In this case no document found on my collection. // ...
DarkScytale's user avatar
0 votes
0 answers
27 views

Vercel Deployment Error: "Schema hasn\'t been registered for model \"Product\"" in Nuxt/Mongoose Serverless Function

I have a Nuxt project that uses Mongoose and a serverless architecture on Vercel. Locally, I can call my cart API endpoint (located at /server/api/cart/index.get.ts) without issues, but when deployed ...
Yousseif Muhammed's user avatar
0 votes
1 answer
109 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
  • 115
1 vote
1 answer
46 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
82 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
  • 172
0 votes
1 answer
53 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
113 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
75 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
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
71 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
58 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
240 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
  • 331
0 votes
1 answer
52 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
2 votes
1 answer
59 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
45 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
76 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
30 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
42 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
1 answer
113 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
39 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
  • 894
-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
193 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
53 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
41 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
63 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
47 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
24 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
128 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
118 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
62 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
74 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
54 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
37 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
89 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
110 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
32 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

1
2 3 4 5
645