Short: What is the Strapi syntax to query my second Mongo database?
Long: Im not able to figure out how to query my second Mongo database. I have the following structure in my database.js (root/config/database.js) file:
To query the default database I just use the strapi.query(). But I cant figure out how I write for example: strapi.query(‘cities’).findOne({ cityId: cityId }); for my courses database. Not able to find this in the documentation nor on Stackoverflow.
Here’s what I would do (seem to be working for me) :
Create a collection called city, add the fields you need, Strapi will then generate the files needed in the api folder.
navigate to api/city/models/city.settings.json, and add at the top of the code
{
“connection”: “courses”,//this being the name of the connector you added in database.js
“kind”: “collectionType”,
“collectionName”: “cities”,
…
}
save the file, build and run again, remember to add the role rights needed.
this will make it seem like the data is stored in the same database, although it is running from the same api, the data will then be stored in the courses database.
hope this helps
welcome to the Strapi Community,
and that’s correct yes,
So how I do it is, I copy the following tables: 'users-permissions_permission, users-permissions_role, strapi_permission, strapi_roleandstrapi_administrator`
Hope this helps