46,822 questions
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 ...
0
votes
0
answers
14
views
session callback throws mongoose__WEBPACK_IMPORTED_MODULE_0___default(...).connect is not a function
I'm using mongoose ^8.11.0 with Auth.js 5.0.0-beta.25
the problem is that is inside the signIn callback I can run this code and work without a slightest problem where both controllers are called:
...
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: '...
1
vote
1
answer
50
views
How to define the correct return type in Higher-Order Functions
I'm using Next.js, Auth.js and mongoose,
my problem is I wanted to wrap all my controllers with a wrapper/helper function called withDBConnection to save me time not establishing a connection with the ...
0
votes
0
answers
25
views
MongoDB Atlas Connection Issue: Error: queryTxt ETIMEOUT cluster0.nqjp7.mongodb.net
MongoDB Atlas Connection Issue: queryTxt ETIMEOUT & ServerSelectionError
I'm trying to connect my Node.js backend to MongoDB Atlas, but I'm getting connection errors.
Error: queryTxt ETIMEOUT ...
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 ...
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,...
-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 ...
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....
-1
votes
0
answers
26
views
Local writing to MongoDB but not deployment
How are you?
Creating a basic app with Nextjs and MongoDB.
Rn just the home page that runs a function that writes to MongoDB
( using mongoose )
repo - https://github.com/MooDevArts/to-do-v4/
I ...
-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....
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 ...
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 ...
0
votes
0
answers
17
views
How to manage a field in mongodb that references a referenced schema?
I have a collection named ‘policies’ which references control in its field 'associatedControls' from collection ‘controls’ and control has a field 'associatedFrameworks' where it references 'framework'...
0
votes
0
answers
23
views
How to remove object from array of object by id of that object? [duplicate]
{
"_id": {
"$oid": "67b645c7261305c279232020"
},
"settings": {
"name": "Field",
"isVisible": true,
"...
-1
votes
0
answers
19
views
Mongoose 'uri' parameter not connecting?
Guys I am decently new to backend and I have been trying to run my application but it just doesn't work, It was working at first but I tweaked it somewhere? could someone this knowledge help?
this is ...
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:
{ ...
0
votes
0
answers
18
views
I need to update mongoose sequence programmatically
I setup npm package "mongoose-sequence": "^6.0.1" and for invoiceDetail schema id field I setup invoiceDetailSchema.plugin(AutoIncrement(mongoose), { id: "invoice_detail_seq&...
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 ...
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 } = ...
0
votes
0
answers
16
views
How to mock GridFSBucket's openUploadStream in Jest for image upload testing?
I'm fairly new to the Jest testing framework and am writing unit tests for a user registration endpoint that handles image uploads using GridFS. I'm getting the following error when running my tests:
...
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 ...
0
votes
0
answers
30
views
Populate in Mongoose doesn't work if I'm using Typescript Error: Schema hasn't been registered for model "Category"
I'm using NextJs 15 with TypeScript and Mongoose, but when I try to populate the Product fields with the category, I get the following error: Error: Schema hasn't been registered for model "...
0
votes
0
answers
34
views
Global keyword error, while connecting to mongoose
I'm trying to connect my nextjs app with MongoDB using mongoose, and I created this mongodb.ts file, which creates a connection with the DB, and returns the cached connection if available, and when I ...
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.".
...
-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 ...
0
votes
0
answers
17
views
mongoose with dynamic properties
pretty new to mongoose, I have my dropdown options in the structure below. This way the overall group holds the collection of dropdown options... a task page would have options for "status",...
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 ...
0
votes
0
answers
12
views
nuxt-mongoose - Vue: Cannot find module #nuxt/mongoose
I installed the nuxt-mongoose module as shown in the documentation. https://docs.arashsheyda.me/nuxt-mongoose/getting-started/setup
but while importing the package, I get an error like this: Vue: ...
0
votes
0
answers
7
views
How to design a mongoose schema to store and check conditional logic?
I'm working on a project where I need to store and evaluate conditional logic in MongoDB using mongoose. For example:
if amount > 1000 AND category = 'food' OR category = 'vacation'
certain ...
1
vote
1
answer
68
views
update mongodb 's array with $addToSet and set array's length with { '$size': '$array' } not working
I am working on mongodb which has model like the below
const appJobSchema = new mongoose.Schema({
data:[
{ type:Schema.Types.Mixed}
],
stat:{
dataCount: { type:Number , ...
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,
...
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)...
0
votes
0
answers
37
views
Lazy loaded module and Service InjectModel
I have a lazy loaded module in App module:
@Module({
imports: [
ThrottlerModule.forRoot([
{
ttl: 60,
limit: 5,
},
]),
ConfigModule.forRoot({
isGlobal: ...
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 ...
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....
2
votes
1
answer
38
views
TypeScript Error While Using MERN Stack: Says TypeError: Invalid schema configuration: `false` is not a valid type at path `select`
I don't know what is wrong here.... im getting this error when i am trying to run my passport config for Google SignIn. This is my schema, i tried almost every solution and now, i am here.
interface ...
1
vote
0
answers
48
views
Mongoose: Populate the _id in an object present in an array of such objects
I have seen similar questions being asked in which there is an array of just ObjectIds needing to be populated. In my case the the array has objects which have 2 properties, one of them being the _id.
...
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 ...
1
vote
1
answer
51
views
Mongoose list property with unique items that can also be empty
Is there a way to have a list property that can be empty and whose items are unique (throughout the whole collection and not just the list itself).
Minimal example of the code I currently have:
const ...
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 } ...
-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-...
0
votes
0
answers
24
views
How to filter on several populate with mongoose?
For a project I'm using mongoose and am stuck in front of a problem
My Contact has a searcher and a createdBy which I populate (both are users)
When I do a search, I want to look for either searcher....
1
vote
1
answer
125
views
Query Performance Issue with Mongoose 8.9.5
I am experiencing a performance issue with all of my queries in Mongoose v8.9.5, where even a simple indexed query is consistently taking at least 1 second to execute, even though the MongoDB explain ...
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....
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 ...
0
votes
0
answers
41
views
Access denied for some Gmail in NextAuth
Learning nextjs after completing Reactjs
In the NextAuth potion I get access denied for my institutional email address but works fine for my personal email.
You may find it usefull:
personal email: ...
0
votes
1
answer
174
views
Using NextAuth (Auth.js) With MongoDB (mongoose) And Middleware
Intro
Hello, in this article, we want to explore how to use NextAuth with MongoDB and Middleware.
“Note: If you want to use middleware with Mongoose, it is not possible.”
Next.js Edge Runtime
...
0
votes
1
answer
38
views
Nested Mongodb query works in compass but not with mongoose
Hi the mongodb query works fine in compass but not with mongoose and nodejs
here's my code
const scanschema = new mongoose.Schema({
toreward: [{
highest: {
type: String,
...
1
vote
1
answer
103
views
Why does an update query only work correctly when I use the await keyword? [duplicate]
try {
const review = await Review.create({
user: user.userid,
place_id: pid,
stars: stars,
content: content,
});
/* await */ User.findByIdAndUpdate(user....