I’m building a server with one front-end and two back-end components. I’ve finished one back-end and I’m now working on the second. Both are Express servers using MongoDB and mongoose for database operations. I need to share the collection schema between them. I have already created a model file on the completed back-end. Do I need to replicate the same model file on the new server I’m developing? What happens if I later need to update the model file? Will I need to update both? I’d really appreciate some advice or examples on the best way to handle this. Thank you!
Have you considered using a shared library for your schemas? This approach can significantly simplify schema management across multiple servers. You could create a separate npm package containing all your Mongoose models and import it into both backend projects. This way, when you need to update a schema, you only do it once in the shared library.
Another option is to use a schema registry service. This could be a separate microservice that stores and serves your schema definitions. Both backends could fetch the latest schema versions from this service on startup or periodically.
Remember to implement proper version control and testing procedures for your shared schemas. This ensures that changes don’t unexpectedly break either backend. Also, consider using database migration tools to keep your actual database structure in sync with your schema definitions.
hey, have u thought about making a shared library for ur schemas? it’s pretty cool. u can make an npm package with all ur mongoose models and import it in both backends. that way, when u gotta update a schema, u only do it once. saves a ton of hassle!
have u considered using a shared npm package for ur models? that way, u only need to update one place when schemas change. it’s super handy! what about version control? how do u currently manage ur codebase? curious to hear more about ur setup!