touchaponk
touchaponk

Reputation: 404

Mongoose / Mongodb migration to MySQL

I have a NodeJS project running with mongodb database (using mongoose).

For a technological constraint reason I need to migrate the app from using mongodb to mysql - is there a way to migrate to mysql without having to rewrite the whole mongoose model files?

PS. although I'm using mongodb all the query is mainly still not on the nested document (I'm querying only by ID or by some first-level attribute) so actually putting nested document into a field in mysql table should still be fine

Upvotes: 3

Views: 2271

Answers (1)

debduttoc
debduttoc

Reputation: 314

I would suggest letting your application run with Mongo for now. Meanwhile write a wrapper for MySQL that would translate your Mongo queries to mysql. Switch to that wrapper once done. Then write another wrapper for Mongo, just in case you need to switch back.

Try and keep all your Database specific function calls in the wrapper. So, that you won't need to do this again and again. Just write a new wrapper for whatever Database you will use and just switch.

And you'll probably need to run some sort of job to migrate your data from Mongo to MySQL.

Upvotes: 2

Related Questions