Questions tagged [mongoose]

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Documentation

Related links

To open a bug or feature request, visit: https://github.com/Automattic/mongoose/issues

For Mongoose, an embeddable web server written in C, use .

Installations

npm install --save mongoose
46587 questions
7
votes
1 answer

Remove referenced documents with mongoose/MongoDB middleware (in 2021 )

I tried all the solutions over stack overflow which relate to deleting referenced documents in MongoDB using node.js. But most of them either have solutions with deprecated methods and some of them do not work at all. I have two models, Parent and…
relu
  • 333
  • 1
  • 3
  • 18
7
votes
5 answers

How to download after uploading a file using express and multer?

I have uploaded the file in my backend filesystem using multer My server is node and client is react. I'm having trouble downloading and displaying the saved file on the client react Whenever I do res.download(file) it just throws an error as…
Phil
  • 435
  • 2
  • 9
  • 28
7
votes
3 answers

How can I add instance/static methods to Mongoose schema when using @nestjs/mongoose? (TypeScript Issues)

When using vanilla Mongoose, it's straight-forward to add methods to Mongoose schemas. It's well-addressed by the Mongoose documentation and several examples can be found. But what about when you're using Mongoose within the context of a Nest app? I…
Greg Thomas
  • 397
  • 3
  • 13
7
votes
3 answers

MongoDB Atlas very slow connection on hot reload

I have been working on a React application that would connect to MongoDB Atlas with Mongoose. Using nodemon and webpack for hot reloading it would reconnect to Mongo within milliseconds every time there was a reload. It was working nicely like this…
mschwartz
  • 188
  • 2
  • 6
7
votes
2 answers

How to properly use Mongoose models in Next.js?

I'm building a Next.js application with TypeScript and MongoDB/Mongoose. I started running into an error when using Mongoose models, which was causing them to attempt an overwrite of the Model every time it was used. Code causing Model Overwrite…
Nicolas
  • 87
  • 2
  • 8
7
votes
1 answer

Getting error: The expression is not callable Mongoose NextJS

I trying to save data to a mongoose model on NextJS page. I get a typescript error on this line: await User.create(data) This expression is not callable. Each member of the union type '{
Hairi
  • 3,318
  • 2
  • 29
  • 68
7
votes
1 answer

NestJS MongoDB unique fields doesn't work

Hey i want do create a user with a unique email. I am using class-validator for additional validation. I found a lot of recommendations here to do uniqueness like that: @Schema() export class User { @Prop() firstName!: string; @Prop() …
7
votes
4 answers

MongooseError: Operation 'featureds.find()` buffering timed out after 10000ms

I have a collection on MongoDB from which I'm trying to query all the elements using find(): const mongoose = require('mongoose'); const Featured = mongoose.model('featured'); module.exports = app => { app.get('/api/featured', async (req, res)…
zendevil
  • 899
  • 4
  • 13
  • 26
7
votes
7 answers

Unable to connect mongoDB using nestjs/mongoose

I have a nest.js node server and I am trying to connect mongoDB data base in the app.module, when the connection string doesn't contains the DB name - the connection to default DB "test" success, but when I specify the DB name- always getting…
user2436448
  • 445
  • 4
  • 7
  • 18
7
votes
5 answers

Mongoose - array of enum strings

I have a Schema that has a property with the type of array of strings that are predefined. This is what I've tried to do: interests: { type: [String], enum: ['football', 'basketball', 'read'], required: true } The thing is that when I'm…
Asaf Baibekov
  • 313
  • 1
  • 5
  • 15
7
votes
2 answers

MongoDB update in array fails: Updating the path 'companies.$.updatedAt' would create a conflict at 'companies.$'

we upgraded (from MongoDB 3.4) to: MongoDB: 4.2.8 Mongoose: 5.9.10 and now we receive those errors. For the smallest example the models are: [company.js] 'use strict'; const Schema = require('mongoose').Schema; module.exports = new Schema({ …
7
votes
1 answer

Mongo connection url fails in Github Actions CI even though credentials are correct

In my CI I need to make sure that my code works with mongo and so I'm using the official mongo docker image and passing my desired credentials as environment variables for the mongo image. build-on-mongo: runs-on: ${{ matrix.os }} env: …
Abir Taheer
  • 2,502
  • 3
  • 12
  • 34
7
votes
2 answers

Content Security Policy: The page’s settings blocked the loading of a resource at inline (“default-src”)

I understand there are many similar questions. However, I'm still new to MERN and I am looking for a simplified answer to this problem. I'm following a tutorial on the MERN stack, the application is a simple expense calculator and all the…
Jordan
  • 117
  • 1
  • 1
  • 11
7
votes
1 answer

How much profile data should go in a JWT token?

I am using JWT for my Node+Express API's route protection; I normally store the user's profile information in the jwt token, unless is granular PII. But I want to know what the best practice is for this. I have the following user schema…
Solomon Bush
  • 165
  • 9
7
votes
2 answers

Mongoose return value from withTransaction callback

I want to utilize mongoose's withTransaction helper particularly for its ability to automatically retry transient transaction errors. However, it seems that the withTransaction helper is incapable of returning data, which is a problem for me. I have…
Infamous911
  • 1,441
  • 2
  • 26
  • 41