-
I have a script runner that uses mongoose, and i wanted to disable updating or creating. so the script wont accidentally overwrite data. is there a way to turn off updates/create in mongoose level? |
Beta Was this translation helpful? Give feedback.
Answered by
vkarpov15
May 23, 2023
Replies: 1 comment
-
Plugins and middleware. Below is a general idea. mongoose.plugin(schema => {
schema.pre('save', () => { throw new Error('save not allowed'); });
schema.pre(['updateOne', 'updateMany', 'findOneAndUpdate', 'findOneAndDelete', 'findOneAndReplace', 'deleteOne', 'deleteMany', 'replaceOne'], () => {
throw new Error('Writes not allowed');
});
}); Another approach would be to define a separate user on your database that only has readonly privileges, and use that user for scripting. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
vexCoder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Plugins and middleware. Below is a general idea.
Another approach would be to define a separate user on your database that only has readonly privileges, and use that user for scripting.