46,888
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 ...
0
votes
0
answers
6
views
Pass previous version of document from pre to post hook in Mongoose
In my mongoose 8.1.3 setup, I have a post findOneAndUpdate hook where I need to compare the previous version of the document to the latest and based on changes run some functions.
My current solution ...
0
votes
1
answer
61
views
Spanish Characters erratically being saved in MongoDB as non utf-8 characters (�)
Seemingly all of a sudden, we started noticing that non traditional characters like "ñ" "¿" or "é" are being saved as a non utf-8 character "�".
We reverted to ...
-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
0
answers
11
views
MongoDB Change Stream Triggered by updatedAt Field Only: How to Handle?
I'm using MongoDB change streams with Mongoose to monitor changes in my Instances collection. Here is the code I'm working with:
Instances.watch(watchFilter, {
fullDocument: "updateLookup",...
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 ...
0
votes
0
answers
11
views
not able to use pre save mongoose hook in nestJs
I have an use case in which before saving a document I need to check if the document is a valid document to be saved based on condition.
To deal with it I am trying to use pre save mongoose hook. But ...
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
1
answer
31
views
Mongoose error: lodash bind no longer accepts a callback function
The upgrade to MongoDB 7 dropped function callbacks, as has been discussed on other threads. Most times it is fairly easy to replace the callback by .then asyn/await etc, as documented at ...
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 ...
0
votes
0
answers
18
views
Patch method gives back "acknowledged": false in Postman
I want to update a product in my PATCH request. I get back "acknowledged": false on my request in Postman. I tried to use $set but I get the same result acknowledged: false from postman.
...
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
16
views
Dockerfile run error. Always having an error "Topology is closed"
I have this error about "Topology is closed" something which unable to connect to mongodb with also with this error MongooseServerSelectionError. Kindly check the error logs below.
I tried ...
1
vote
0
answers
42
views
TypeScript Error: Argument of type 'unknown' is not assignable to parameter of type 'string | ObjectId'
I feel like this issue is simple to resolve. However, for the life of me I cannot come up with a resolution for this error.
folderSchema.ts:
import mongoose, { Document, Schema, model } from "...
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
33
views
Error while making a schema with mongoose
I am exepriencing an issue with my schema I made with mongoose in Typescript.
This is the current code:
import { Schema, model } from "mongoose";
interface ISchema {
guildId: string;
...
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
20
views
Model references do not share data (mongoose)
I am a big confused on this, but when a user sends a POST request to create a social media post, the post gets created under their username, but when i attempt to access the 'posts' field when i try ...
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
0
answers
21
views
mongoose.connection.db is undefined in NestJS
I am willing to run some e2e tests for my application. I want my database to be wiped off after running all test cases. I am using Mongoose to integrate with MongoDB. The problem is that mongoose....
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 },
...
1
vote
0
answers
25
views
How to adjust mongoose query for Atlas Search?
This is my Index Definition in Monodb Atlas Search.
{
"mappings": {
"dynamic": false,
"fields": {
"title": {
"type": "...
1
vote
1
answer
28
views
Mongodb Last 3 months data. Example: 2024's (March,April,May) and also 2023's(November,December) + 2024's (January)
I am trying to see last three months data, but my code gives me all data. It doesnt give last three months data.
You can see the result in both cases i am getting data from 2023. Ex: "2023-12-...
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
28
views
Mongodb & Express, post error message: buffering timed out after 10000ms
Nearly all answers I've found to this issue result in people saying "you aren't connected to MongoDB" or "you need to create an async await to connect to the database," but I am ...
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 ...
0
votes
0
answers
17
views
Writing a Mongoose/MongoDB Lookup Query Without Using $text
(Before I get too deep into a rabbit hole where I beat my head against the wall the whole way down, I figured I'd ask for help.)
To my understanding, the conventional way of doing a lookup is by using ...
1
vote
0
answers
50
views
returning specific status code , message in server actions
I have this code below, What I'm trying to achieve is returning error (specific message and status code) instead of getting always 500 status code, if i tried to register with an existing email,I'm ...
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
1
answer
41
views
The error was caused by importing 'mongoose/dist/browser.umd.js' in './config/mongodb/index.ts'
I created my own application on next.js version 14 with mogoose version ^8.4.4 that works well on my local.
I tried to deploy my next application on Vercel but I got this on console:
Failed to compile....
0
votes
0
answers
25
views
Mongoose Shows No Sign of Connection with Mac
mongoose.connect(process.env.NEXT_PUBLIC_MONGO_URI)
.then(() => {
console.log("Connected to MongoDB");
app.listen(3001, () => {
console.log("Server ...
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
0
answers
29
views
Getting issue while passing _id to find an existing item
Creating a job portal website using react and mongodb. A user logins and save the job. So a model is created to save the jobs and created Controller. Before saving a job checks if it is exist or not ...
-1
votes
1
answer
19
views
Howto update inventory count on nest product
I have an nested Product inventory object. However, when I increment the inventory count the value does not get incremented. Here is the object structure. The inventoryDetails count always remains 0, ...
0
votes
1
answer
37
views
Using $or to get ratings average of the selected values, for example from 4 to 4.9 doesn't work
In my DB the ratingsAverage's type is Number. I want to implement filtering functionality depending on the ratings. For example, if the user selects 4, the result will be the ratings that fall within ...
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 ...
0
votes
0
answers
12
views
Mongoose sub-schemas do not save data and have non-iterable keys
Suppose you have a mongoose schema with a sub schema
const userSchema = new Schema({
name: {
type: Schema.Types.String
}
})
const eventSchema = new Schema({
name: {
type: Shema.Types....