Wednesday 26 August 2020

Does anyone have some example code for doing migrations with middleware for MongoDB and Mongoose?

I was reading about how to migrate data after changing a MongoDB schema. I saw this thread:https://www.reddit.com/r/node/comments/9lruth/question_how_do_you_deal_with_mongodb/That mentions that you can do it using middleware by checking the schema version by checking the versionKey or __v, and if the a version of a document needs to be updated you can write some code to do so in a middleware function.However, I didn't see any actual code on how to do this on Stackoverflow or Reddit. Does anyone have an example on how to do so, or can someone tell me which Mongoose middleware I'm supposed to use to check a document's __v and update it if need be?I'm also aware I can query the entire DB and update documents that way, but I think this approach is an interesting idea.

Submitted August 26, 2020 at 07:05PM by taimoor_apps

No comments:

Post a Comment