node.js - How can I switch between a live and a production database without duplicating code? -


here situation. have extensive rest based api connects mongodb database using mongoose. api written standard "mean" stack application.

currently, when developer queries api they're connecting live production database. want have exact duplicate database "staging" database, new data added first, vetted on period of time, , move live database. want developers able query either 1 modifying query.

i started looking mongoose documentation, , appears though models tied db connection, , if want have multiple connections have have multiple models, 1 each connection. nightmare of wet code , not path want take.

what want not touch of code @ , have switch changes proper database given query. question is, how can achieve this? possible? documentation seems imply not.

rather trying maintain connections 2 environments in same code base have considered setting stage version of application? database connects set through environment variable or other configuration option.

the developers still have make change query 1 or other , migrate data stage database production/live database once have finished vetting process.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -