All Questions
32,276
questions
0
votes
0
answers
22
views
Error: querySrv EREFUSED _mongodb._tcp.cluster0.vzygb.mongodb.net while connecting to mongodb
I've tried everything using chatgpt and configuring it again. Creating a new project and then creating a cluster and then doing all the process again.
But this error seems to be stuck there. what is ...
-1
votes
3
answers
44
views
MongoDB ECCONREFUSED when connecting to MongoDB Compass
I am trying to learn Node.JS from scratch. I am trying to connect index.js to MongoDB compass when I get the error:
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
at ...
0
votes
1
answer
24
views
Retrieving a Single Numeric Device ID from a Mongoose Schema
How can I retrieve the deviceId as a single numeric value in my Mongoose schema and Express.js controller?
I'm using Mongoose with Express.js to save car records, and I've defined a deviceId field as ...
1
vote
0
answers
37
views
Building time-bound leaderboard in Node.JS and MongoDB
We have a document for each user. We award them "oranges" (in-game points) for completing activities.
We store the points given like this:
We have their epoch time along with the oranges ...
0
votes
0
answers
39
views
Create a history table and keep track of all the updates to a document
I have a NestJS application that uses mongoose and MongoDB. I need to capture all changes/versions of this document so that I can display this as a history of the document, what changes were made by ...
1
vote
1
answer
31
views
Mongoose _id is not working correctly for custom value instead of default value
Hay! I am working with mongoose where I have collection named tag and here is it's schema
const tagSchema = new Schema<ITag, ITagModel>(
{
_id: {
type: String,
unique: true,
...
0
votes
1
answer
40
views
NestJS Mongoose Connection Error: "MongooseServerSelectionError: connect ECONNREFUSED ::1:27017" [duplicate]
I'm working on a NestJS application that connects to a MongoDB database using the Mongoose module. Everything was working fine until I encountered the following error:
[Nest] 3372 - 08/24/2024, 9:32:...
0
votes
1
answer
32
views
Mongoose Validation Error on lastUpdated Field Despite Setting It Before Save
I'm running into a bit of an issue with Mongoose in my Node.js/Express application, and I would greatly appreciate your help. The problem occurs when I try to update a Restaurant document in MongoDB. ...
0
votes
0
answers
16
views
node js $strLenCP requires a string argument, found: missing',
router.get("/find", async function (req, res) {
// var regex = new RegExp("react", "i");
var date1 = new Date("2024-08-22");
var date2 = new Date("...
0
votes
1
answer
38
views
Mongoose Plugin to filter soft deleted in array docs and root docs using find() and perform soft delete on array docs and root docs [closed]
Implementing a Mongoose Plugin for Soft Delete Array docs and root docs and Filtering soft deleted Array docs and root docs.
I am developing a Mongoose plugin to handle soft deletion and filtering of ...
0
votes
0
answers
32
views
Unable to add id in URL request through req params
I want to retrieve product by id from server in mongoose but req.params.id is not working.
I replaced req.params.id with id number to see if there is any other problem but it worked fine.
Here is the ...
0
votes
1
answer
41
views
Cast to ObjectId failed for value (array) at path (pathName) because of BSONError
Not sure if i did wrong, but I'm trying to POST an array with ObjectIds into a model with the type being ObjectId (see model), and it just returns
"Cast to ObjectId failed for value "['...
0
votes
0
answers
15
views
mongoose.connect is not a function
I am using nextJs app router and mongodb and this is the file where i connect to the database
import mongoose from 'mongoose'
let isConnected = false;
export const connectToDB = async () => {
...
0
votes
1
answer
24
views
Initialization subdocuments models with Typegoose
We're migrating our project from pure Mongoose to Typegoose, overall we're happy but there's one issue that always bothering us.
Let's say we have a simple model:
class Animal {
@prop()
public ...
-1
votes
3
answers
51
views
Mongoose findOne always return null
This is the user snippet
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
name: { type: String, required: true },
lastName: { type: String, required: true },
...
2
votes
0
answers
78
views
Handling null value in response, using axios and mongoose schema
When doing getOrder, it returns a response of user:null. Because of this, my database is full of orders without user names. What I want is to display the user's _id in the newly created order when ...
0
votes
0
answers
37
views
$gte for dates works in MongoDB Atlas, but not in Mongoose
I'm trying to query for products that are still on sale using this schema and filter:
// Model
const ProductSchema = new Schema({
sale: {
until: Schema.Types.Date
}
})
const Products = model('...
0
votes
1
answer
48
views
How to add methods to query an object in mongoose using typescript?
The problem is more related to the typescript. I need these methods to check the returned result after querying the db.
const user = await User.findOne({idUser: 1}).isAbsent(400)// this status code ...
1
vote
0
answers
43
views
Get all records in a mongo collection returns empty array
I have a mongo database named "photos-album", and a collection named "users".
I'm trying to fetch all users in mongo, but I get empty array although I do have users in my users ...
1
vote
0
answers
37
views
How to handle : Error : image: Cast to string failed for value; NodeJS
So I'm working on expressJs and mongoosh connecting server to DataBase. For inserting documents I've created different file "data.js" and require this data.js to index.js.Mainly error is ...
1
vote
1
answer
35
views
BSONTypeError: Unsupported type BigInt, please use Decimal128
I'm trying to create a sort of timer command with Discord.js and MongoDB. I currently use mongoose as the wrapper. I am also using Agenda to automatically delete the timers from the database after the ...
1
vote
1
answer
44
views
Mongoose.save() doesn't seem to actually change anything in the database
I'm trying to update an object within an array in a MongoDB database. I don't seem to be getting very far with Googling the problem, and Mongo doesn't seem to be coming back with any errors so I'm a ...
0
votes
0
answers
35
views
mongoose.Model.findOne always returning null
I have the following mongoose schema:
export interface MusicInput {
title: string
artist: string
album: string
genre: string
userId?: string // maybe make this mongoose.type.ObjectId
}
...
0
votes
1
answer
34
views
Difficulty using mongoose-paginate-v2 for pagination in TypeScript
I'm encountering issues with pagination using mongoose-paginate-v2 in my TypeScript application. When I attempt to paginate my OfflineMacroAction collection, I'm not receiving any results despite ...
4
votes
0
answers
44
views
Issue with MongoDB Query Using $ne: null on Array Fields
Context
We are working with MongoDB queries in a Node.js application, where we need to filter documents based on whether an array field (specifically, a field within a nested array) exists and is not ...
0
votes
0
answers
31
views
Node.js - Mongoose BSON field 'FindCommandRequest.jsonSchema' is an unknown field
I’m currently working on setting up client-side field level encryption (CSFLE) using Node.js, Express, and Mongoose, following the tutorial for Use Automatic Client-Side Field Level Encryption with ...
0
votes
1
answer
26
views
Delegate missing instance methods to mongoose document
I'm building a Node.js application using MongoDB and Mongoose. I have a 'companies' collection with the following schema:
// app/schemas/company.js
const AboutScheme = new Schema({
slogan: String,
...
0
votes
0
answers
30
views
Getting ERR_CONNECTION_REFUSED in React and Node.js Application
I keep getting errors
ShoppingCart.js:16 GET http://localhost:5001/api/cart net::ERR_CONNECTION_REFUSED
signup.js:71 POST http://localhost:5001/api/users/register net::ERR_CONNECTION_REFUSED.
I'm ...
-1
votes
0
answers
42
views
Node.js Module Intellisense not work correctly
I have installed vscode extension of Node.js Modules intellisense
The suggestion is work when I call all of models methods as below
https://mongoosejs.com/docs/models.html
Tour.find()
Tour....
2
votes
1
answer
65
views
Delete a specific field meeting specific conditions from an object in a collection
I have searched the web for possible solutions. Basically a field needs to be deleted where the id of an object in an array of objects meets a specific condition.
As a newbie to Mongodb I am not sure ...
0
votes
1
answer
24
views
Aggregate vs Populate methods when to use one in nodejs Mongose
I am creating asset managment tool for warehouse and I have Warehouse , Asset, Category models. I want to get the overall stats of each warehouse like , total assets and how many of them is active or ...
0
votes
0
answers
40
views
React / API route is unable to post the form data
I have an Add Product form. In this form, there is an Upload Image field to upload jpg and png from your computer. Anyway it doesn't work and products get uploaded without image. My aim is to convert ...
0
votes
0
answers
22
views
VersionError when saving Mongojs document in child_process
I'm doing some heavy computing in a child process so that it doesn't hang up the main thread. However, I receive the following error when trying to save a document at the end of that process: ...
1
vote
0
answers
34
views
Search products (documents) based on their ratings using mongoose
I was creating a full stack e-commerce website, when i came across this problem. I wanted to add a search filtering based on reviews star. The client sends query and minRatings to the server and the ...
0
votes
1
answer
35
views
Mongoose connection drops at all endpoints
I’ve been working on a project intermittently for some time now. Recently, after transitioning to a new computer, and router none of my endpoints respond
I’ve taken several troubleshooting steps ...
0
votes
0
answers
9
views
OverwriteModelError: Cannot overwrite AddOnsDatabase model once compiled. [Typescript]
Im using nextjs
i keep getting the error
OverwriteModelError: Cannot overwrite AddOnsDatabase model once compiled.
to fix this error i am using the OR operator to check if the model already exists
...
0
votes
0
answers
27
views
Switch the Database of the default mongoose connection
In trying to limit the number of connections in my web application I switched from using mongoose.createConnection() to mongoose.connect()
Which works perfectly if your only ever using one database. ...
0
votes
1
answer
63
views
Store object array of product size and colors in mongo DB
I need to store object array of product size and colors.
Is it possible in mongo DB.(Because in ms sql it is not allowed).If so how the schema should be?.Sample object structure is shown below
{
color ...
0
votes
2
answers
32
views
How do I use the find() method to query a mongoose schema with an enum field (can hold multiple values (array)) that includes a particular value?
I have this schema:
const User = new Schema({
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
mobile: {
...
0
votes
0
answers
32
views
Have an issue with types when creating a Fastify plugin to decorate mongoose models using Zod
I have created a Fastify plugin to decorate Mongoose models, adding them to the Fastify interface:
declare module 'fastify' {
export interface FastifyInstance {
models: {
[key: ...
0
votes
0
answers
23
views
I want to reference a mongodb subdocumnent with a subdocument in the same array. I do not want to store categories in a separate document
I want to reference a mongodb subdocumnent with a subdocument in the same array. I do not want to store categories in a separate document.
const CategorySchema = new Schema(
{
name: { ...
0
votes
0
answers
109
views
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
I'm having problem using mongodb. I downloaded as said in docs for debian (i'm using kali linux) and first day it was fine. Everything i did worked well. Now for second boot up it started giving me ...
0
votes
0
answers
19
views
Mongoose populate is breaking my Serverless application when upgrading to Node JS 20X
I have a REST API that I'm migrating from Node16 to Node20 in Serverless.
Everything works fine except the populate method for my queries.
Im using:
[email protected]
[email protected]
node v20.15.1
This ...
2
votes
1
answer
61
views
why new added schema property reflects on returned mongodb documents?
I know that adding new property(s) in our mongoose schema won't reflect to existing data from our mongodb documents unless you do db.collection.update(...) so.
But why mongoose adds this new property(...
0
votes
1
answer
39
views
Update conflict in mongoose
I'm having an issue with updating a user's count field in MongoDB using Mongoose. Here is my schema and the code I'm using:
const user=new Schema({
username:String,
count:{
type:Number,...
1
vote
0
answers
49
views
How to get the model name from a Mongoose duplicate error
In the application, I have defined two models. The first model is the movie model, and the second model is the user model. In the movie model, movie name is a unique field, and in the user model, ...
0
votes
1
answer
68
views
What happens when abortTransation() or endSession() fails using mongoose?
I have a typical transaction operation using mongoose in my nodeJS/Express application:
let session = null;
try {
session = await mongoose.startSession();
await User.create({ ... });
await Otp....
1
vote
0
answers
34
views
Mongoose and AWS Lambda optimize connection
I built a lambda that reads and writes from a DB. Using Node JS and Mongoose for MongoDB (last versions).
Obviously, after few dozens of triggers, I get errors "unable to connect" or "...
0
votes
2
answers
61
views
Using an outer Boolean variable inside a mongodb aggregation pipe line logical operator $or
I have to check a Boolean flag and base on its condition return different data result.
for example I have a collection of books and their prices, normal result of query is prices matching 10, BUT IF ...
0
votes
0
answers
40
views
Why isn't it updating the elements mongdb database?
products.map(async (prdct) => {
try {
let srchdPrdct = await ProductSchema.findById(prdct.product);
let dscntPrice =
Math.round(
srchdPrdct.price *
83.49 *
...