Multiple databases with noSQL not working

Hello everyone!

I am using Typescript with MongoDB with “forest-express-mongoose”: “^8.4.3”.

I want to plug multiple databases into my project, and am having trouble.

My databases.ts file

My forestadmin middleware file

I have created two folders in my models folder and in there is have an index.ts file, which I am using to export my models. this is what my index.ts file looks like

For some reason, I am unable to run both databases at the same time. If I comment one connection out of the connections array, everything works, however, if I use both of them, I get forestadmin error screen.

Kindly help me out.

Tanish

Hey @tanish :wave:

Your index.ts seems to be missing a few parts compared to a forest-cli generated project.
We have a few threads on the community that may help fix your issue.

Could you try the index.[t|j]s provided in the thread?

Let me know if that fixes the issue, otherwise share the content of the index.ts once you modified it & the associated error.

Thanks in advance :pray:

Thank you for your response. I have investigated this for many hours and I am facing one small issue. I have now modified it so that I don’t need to divide my schemas into subfolders because of using multiple databases and hosting them from one single index.ts and one models folder. As you can see, this simplifies certain aspects. Therefore, when I try to run the project, I am unable to. However, if I comment out one connection, the other schemas work and vice versa.

When I try to run forest schema:update from my root folder or my dist folder, I get the error

× The configuration file “/Users/tanishpanjwani/Desktop/dibsy/dibsy-dev/v1/dibsy-forest/config/databases.js” does not exist.

My models/index.ts file

My databases.ts file

My middleware/forestadmin file.

Please suggest a solution to this.

Tanish

Hi @tanish :wave: I think you need to run this command

forest schema:update -c dist/config/databases.js -o outputFolder

instead of the simple one.
See the forest schema:update -h for more informations.

Let me know.

1 Like

Hello!

I am getting this new error now saying

× An unexpected error occurred. Please reach out for help in our Developers community (https://community.forestadmin.com/) or create a Github issue with following error: databasesConfig.map is not a function

I have tried changing directories, and even tried by changing sourceMap value in my tsconfig file but to no avail

Hey :wave: sorry I forgot one thing,
Unfortunately, our CLI is developed for JavaScript, and the way we import databaseConfig file does not match. So please change the export in config/databases.ts to

export = databaseConfiguration;

it should work, let me know.

Hello Arnaud,

I was able to resolve the issue after much refactoring and trial and error. It seems that I was partially following this document Plug multiple NoSQL databases - Documentation which is very outdated and misleading causing me more confusion. The forest admin community post here ISSUE: Plug multiple NoSQL databases was much more helpful in helping me resolve the issue. I request you to update or remove the article.

Thanks!
Tanish

1 Like

I followed your feedback to our team.
thank you :pray: