3,370 questions
0
votes
0
answers
61
views
NestJS converting mongodb snake case to camel case format but it returns undefined
I'm currently trying to create the model using nestjs mongoose schema, and i want to convert the mongodb data from snake case to camel case in my schema layer like this:
export type ...
2
votes
0
answers
133
views
MongoDB Atlas connection error: queryTxt ETIMEOUT with Mongoose
Mongoose connection to MongoDB Atlas fails with queryTxt ETIMEOUT
I’m trying to connect my Node.js app to MongoDB Atlas using Mongoose, but the connection fails with a timeout error.
Here’s the error ...
0
votes
0
answers
39
views
Mongoose populate plugin with Typescript
I've been trying to create a plugin which implements a query and schema method that populates a user field and selects some inner fields from it (firstName, lastName, image).
I just can't seem to make ...
0
votes
0
answers
28
views
How do I change existing string type property into reference type property?
There is an existing collection1 having a property which is an id of another collection2 but the data type is string. How do I convert this property to an objectId type with reference to the other ...
0
votes
0
answers
33
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'...
2
votes
1
answer
107
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
35
views
On Schema , Model and Mongoose
I am trying to understand the Schema, Model and Mongoose based on their type. I am really confused regarding is Schema a class or just look similar to class? Is Model a class or just behave like class ...
0
votes
0
answers
32
views
How to use multiple custom Mongoose Schemas as sub-schemas for the type field instead of Schema.Types.Mixed?
I'm working with Mongoose to create a StepperDataSchema that contains a celebratorDetails field. This field can have one of two possible sub-schema structures:
1.BirthdayCelebratorDetailsSchema
2....
1
vote
0
answers
41
views
Can not use $rename to rename property of documents
I have a mongoose Schema and I would like to rename a certain property named 'template' to 'document'.
If I would first change name of the property from 'template' to 'document' in the Schema and than ...
0
votes
1
answer
53
views
How to use enum with values in Typescript?
Note: I'm a beginner level person in typescript, so, instead of downvoting my question, please try to elaborate the concept.
I'm having trouble using enum in my code. I want to use an enum(with values)...
0
votes
1
answer
59
views
Mongoose runValidators: true is giving wrong validate error when findOneAndUpdate() is using
I have a function in express js to update my project like below:
projectController.ts
export async function updateProjectStatus(req: Request, res: Response) {
try {
const projectCode = req....
1
vote
2
answers
48
views
Unable to update a course by its id using mongoDB and mongoose in noddejs
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/mongo-exercise")
.then( ()=> console.log("Connected to MongoDB..."))
.catch(err => console....
0
votes
1
answer
32
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
1
answer
25
views
Mongoose does not save object with discriminated property
I created a ProductSchema which is extended by a CategorizedProductSchema. The difference between them is that the CategorizedProductSchema has an attribute category which is of type CategorySchema. ...
0
votes
2
answers
46
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
41
views
Mongoose custom schema type cast method returns Promise<pending> TypeScript error
Question:
I'm implementing a custom Mongoose schema type called Password for handling password hashing using bcrypt. However, I'm encountering a TypeScript error specifically related to the return ...
0
votes
1
answer
49
views
How to search field's in a MongoDB Schema which has Reference to another Schema?
I want to search product with its name in below DOC Schema. But the products are stored as reference to another Product Schema with _id. Below is the code -
DOC Schema
import mongoose from "...
0
votes
1
answer
76
views
'ERROR [HttpExceptionFilter] Maximum call stack size exceeded' when implement schema using mongoose in NestJS
I'm using NestJS. I'm making a schema for my mongodb, the schema looks like this:
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { ProductInCartDto } from "../...
1
vote
1
answer
192
views
How to convert Decimal128 value to Float value in Node.js / Mongoose?
I got the following output from the Node.js backend server when I use the Orders.find() to find some documents from the MongoDB database.
{
_id: new ObjectId('6672a038a102620d14a93cac'),
...
0
votes
1
answer
58
views
Error message in a custom validator in a mongoose Schema
i am a total begginer. I am trying to send a specific error message in password and password confirm validator in a mongoose schema.
const mongoose = require('mongoose');
const userSchema = new ...
-1
votes
1
answer
65
views
Error when using required field in schema in mongoose [closed]
//controller:
const Product = require("../models/productModel");
//Create product
exports.createProduct = async (req, res, next) => {
const product = await Product.create(req.body);
...
0
votes
3
answers
82
views
failed to generate unique invite code with randomlize library in mongodb
I made a user schema based on mongoose or mongodb, in which there is a invitation code and this code is always unique in the database.
import randomize from 'randomatic';
const userSchema = new ...
0
votes
1
answer
50
views
Mongoose middleware is not being called for findByIdAndDelete
const mongoose = require('mongoose');
const { Schema } = mongoose;
main().catch(err => console.log(err));
async function main() {
await mongoose.connect('mongodb://127.0.0.1:27017/...
0
votes
0
answers
51
views
extra fields in $text error when doing a text search on a mongoose collection
I have indexes setup on customer schema like below
CustomerSchema.index({ firstName: 1, dob: 1 });
CustomerSchema.index({ firstName: 1, lastName: 1, dob: 1 });
CustomerSchema.index({
firstName: '...
0
votes
2
answers
84
views
Querying for deeply nested subdocuments in Mongoose
I've been having trouble trying to query for a deeply nested subdocument while using Mongoose.
My DB structure is like this:
{
"_id": "662aa6ccae109745e30dc664",
"...