27 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
Score of 3
0 answers
84 views
How to check if a document is mongoose sub schema in middleware?
I am building a multi-tenant application, and I am using a global plugin instead of adding a plugin to each model one by one. This plugin will handle adding organizationId during filters, saving, and ...
- reputation score 964
Score of 0
1 answer
253 views
How to register same mongoose hook for multiple methods in TypeScript?
Based on the answer in How to register same mongoose hook for multiple methods?
const hooks = [ 'find', 'findOne', 'update' ];
UserSchema.pre( hooks, function( next ) {
// stuff
}
The code above ...
- reputation score 2947
Score of 1
0 answers
82 views
Cascade mongoose implement rollback when having errors
I am implement cascade like for mongodb using pre remove middleware of mongoose follow : Cascade style delete in Mongoose
But I when having errors it not rollback deleted data. So how can we start ...
- reputation score 886
Score of 2
2 answers
851 views
Mongoose Query Middleware Error(Query has already execute)
When I execute this model,I get error. Please solve this question. This problem brought me headache.
Opposed to using 'Content here, content here', making it look like readable English, many desktop ...
- reputation score 21
Score of 1
0 answers
1337 views
using mongoose middleware with SchemaFactory
I am trying to use a mongoose middleware to recursively delete references to this object in another objects array (delete task references in taskList with the id from task)
The problematic function:
...
- reputation score 1427
Score of 1
1 answer
2151 views
How to register same mongoose hook for multiple methods?
I want to execute same script in the pre-hook with multiple methods like this:
UserSchema.pre("findOne", function(next) {
console.log("Common code");
});
&
UserSchema.pre(&...
- reputation score 129
Score of 0
1 answer
690 views
why do i have to use next() in mongoose pre save middleware
userschema.pre('save',async function(next){
const user =this;
if(user.isModified('password')){
user.password=await bcrypt(user.password,8)
}
next()
})
i am first time ...
- reputation score 13
Score of 2
0 answers
173 views
adding a pre middleware in the model to be extended in mongoose
i am using "mongoose-extend-schema": "^1.0.0" with mongoose to add a base schema to all other schemas.
here is my code:
import mongoose from "mongoose";
interface ...
- reputation score 1025
Score of 0
1 answer
269 views
post middleware in mongoose not atomizing operation? still creates document even though next(err) is called
I have a model, let's call it Client and i have another model called Accounts. They are from difference collections, a client can have many different accounts. I reference the accounts within the ...
Score of 0
1 answer
197 views
Can Mongoose middleware populate then sort an array of references?
I'm trying to sort an internal array of document references in a document by the values in the referenced documents. I'd like to do this every time I run a query so if I can do this with a query sort(...
- reputation score 496
Score of 3
1 answer
1896 views
Mongoose | Middleware | Rollback operations performed by pre/post hooks when an error is thrown
Considering the code below, how can a transaction be implemented in order to ensure that someParentDocument doesn't get deleted and any operations performed inside the hooks are rolledback, when an ...
- reputation score 1558
Score of 1
1 answer
1183 views
How to silently skip saving a document when pre-save hook fails in Mongoose?
I'm adding a series of documents to the database. Each of these documents is validated in a pre-save hook. I want Mongoose to ignore saving that particular document that fails the validation without ...
- reputation score 222
Score of 2
2 answers
1486 views
How to detect all changes,including deletion, made to a collection in MongoDB/Mongoose?
I have an app that uses MongoDB via mongoose. On the app there is a collection called Notifications. I would like to detect every time there is a change in that collection(including deleting a ...
- reputation score 8044
Score of 0
0 answers
85 views
difference between calling of pre-middleware with next and without next
i wan't to know what's the difference between calling the middleware with next and without next
example without next
All middleware run perfectly fine without next also
tourSchema.pre('save', ...
- reputation score 323
Score of 1
2 answers
2268 views
pre save middleware in mongoose
i am first time using pre save middleware and getting a bit confusion in it.
It runs perfectly fine and also my save method is getting executed eventhough i am not calling the next()
case 1
...
- reputation score 323