You can easily connect a LoopBack application to multiple different data sources.
Add a data source
You're going to add a MongoDB data source in addition to the MySQL data source created in 将API连接至一个数据源.
$ slc loopback:datasource
When prompted, respond as follows:
? Enter the data-source name: mongoDs ? Select the connector for mongoDs: MongoDB (supported by StrongLoop)
Install MongoDB connector
$ npm install --save loopback-connector-mongodb
Configure data source
REVIEW COMMENT from Rand
Do we want to give the option to connect to your own MongoDB server?
Do we want to give the option to connect to your own MongoDB server?
Edit datasources.json
to configure the data source so that it connects to the StrongLoop demo MongoDB server. Add the following JSON after the two existing data source definitions (for "db" and "mysqlDs"):
server/datasources.json
... "mongoDs": { "name": "mongoDs", "connector": "mongodb", "host": "demo.strongloop.com", "port": 27017, "database": "getting_started_intermediate", "username": "demo", "password": "L00pBack" }
Next:
Continue to Create new models.