By default, a DB object is exposed when the CloudCode task is invoked.
Accessing Other Deployments
To access a different deployment within the same app or a different app, a new DB object can be created:
// Same app, different deploymentconstotherDB=awaitCloudCode.createDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/','{backend-deployment-id}', {username:'{backend-deployment-id}', password:'mypassword'});constotherDB=awaitCloudCode.createDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/','{backend-deployment-id}', {token:'mytoken'});// ExampleconstotherDB=awaitCloudCode.createDB('https://62d541f4156bc4dd685318da.backend.us.journeyapps.com/','62d541ff9f54b7000706c585', {token:'mytoken'});// Different appconstotherDB=awaitCloudCode.createRemoteDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/','{backend-deployment-id}', {username:'{backend-deployment-id}', password:'mypassword'});constotherDB=awaitCloudCode.createRemoteDB('https://{app-deployment-id}.backend.{region-code}.journeyapps.com/','{backend-deployment-id}', {token:'mytoken'});// ExampleconstotherDB=awaitCloudCode.createRemoteDB('https://62d541f4156bc4dd685318da.backend.us.journeyapps.com/','62d541ff9f54b7000706c585', {token:'mytoken'});
Accessing other apps with different data models
If you try to use this to access another app's DB, make sure to use createRemoteDB and not createDB. Otherwise, you'll get errors like TypeError: Cannot read property 'where' of undefined