I'm trying to connect mongodb and mysql on Loopback4
How to config datasource.json and model as Content's model conecter mongoDB, User's model conecter mysql
If you are using lookback 4 , then you can just use the cli for this purpose.
# lb4 datasource
Then answer the wizard questions such as:
Then loopback4 will show you the list of drivers you can choose from, in this case choose mongodb driver.
that´s all, loopback4 will install the chosen driver and will create a json format configuration file located at src/datasources/datasource.json where you can change the values entered during the configuration.
I hope that helps.
You can take these examples to try to connect:
To MongoDB
{
"name": "dbname",
"connector": "mongodb",
"url": "",
"host": "localhost",
"port": 27017,
"user": "",
"password": "",
"database": "dbname",
"useNewUrlParser": true
}
To MySQL
{
"name": "dbname",
"connector": "mysql",
"host": "localhost",
"port": 3306,
"user": "",
"password": "",
"database": "dbname"
}
I've used both of them and they work correctly. Of course those values have been taken from my local development environment, and they are not recommended for production.