Using firebase-admin To Connect to a Firestore Database other than (default)
Use a firebase-admin Package with multi-db Support
Before reading on, make sure you have a recent enough version of firebase-admin installed (from what I read, 11+ has multi-db support). Otherwise install it with npm install firebase-admin@lates:
$ npm list firebase-admin
firebase-admin@1.0.0 ~/projects/firebase-setup/firebase-admin
└── firebase-admin@13.2.0Use settings() to set the DB
This is what you came here for, the settings() call.
Set the databaseId with the settings() call
const admin = require('firebase-admin');
admin.initializeApp({ /* ... */ });
const db = admin.firestore();
db.settings({ databaseId: 'my-other-db' }); // THIS WORKSAI suggested variations of the following
const db = admin.firestore({ databaseId: 'my-other-db' }); // won't work
const db = admin.firestore().database('my-other-db'); // won't work
const db = admin.firestore().databaseId('my-other-db'); // won't workAll of those result in errors similar to these:
Hope this helps someone.