FlyOrDie
FlyOrDie

Reputation: 3

Two nodejs applications, one mongodb database

Good day! I have created an application using nodejs + mongoose and now I want to make something like a superuser application. I need my admin panel application to connect to the same database. So, i have a question.

Should i store the same Schema file in both applications to have an ability to use my Schema methods? In other words, what is the best way to create one more API using the same db?

Thank you!

Upvotes: 0

Views: 1334

Answers (2)

Don F.
Don F.

Reputation: 123

If I'm not mistaken, why not create another service that only interacts with the database? That way, the systems will refer to the same schema/DB regardless of which application you want to connect to it. So the superuser application and the normal application will just query the DB microservice that interacts the database.

Pro: source of truth for the schema for all applications and the DB queries will just be API calls

Con: additional overhead in creating your ecosystem

Upvotes: 2

clay
clay

Reputation: 6017

If you are using the same DB from two different applications, you will want to make sure those schemas are the same between the two. If one changes its inputs, the other might need to change its display (or risk not expecting all that information). Keep all this in mind during your release process.

I would suggest making the schemas an external library to both, or have the admin panel require the current app. You'll avoid getting two sets out of sync and know to look at one place for the schema definitions.

Upvotes: 1

Related Questions