Reputation: 1748
I'm trying to use the admin SDK for firebase on my machine. When I try to get the users collection I get Error: 14 UNAVAILABLE: No connection established
. Writing to firestore also does nothing. How can I fix this?
EDIT From the docs:
The Firebase Admin SDKs automatically connect to the Cloud Firestore emulator when the FIRESTORE_EMULATOR_HOST environment variable is set
I do have that environment variable set but I'm trying to connect to production. How can I instruct the SDK to do this?
index.js
const admin = require("firebase-admin");
const serviceAccount = require("./serviceAccount.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: ""
});
const snapshot = admin.firestore().collection('users').get().then((snapshot)=>{
snapshot.forEach((doc) => {
console.log(doc.id, '=>', doc.data());
});
}).catch(e=>{
console.error(e);
});
The full error log:
PS C:\Users\simeon.ramjit\Documents\projects\controllino-server> node index
Error: 14 UNAVAILABLE: No connection established
at Object.callErrorFromStatus (C:\Users\simeon.ramjit\Documents\projects\controllino-server\node_modules\@grpc\grpc-js\build\src\call.js:31:26)
at Object.onReceiveStatus (C:\Users\simeon.ramjit\Documents\projects\controllino-server\node_modules\@grpc\grpc-js\build\src\client.js:330:49)
at Object.onReceiveStatus (C:\Users\simeon.ramjit\Documents\projects\controllino-server\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:299:181)
at C:\Users\simeon.ramjit\Documents\projects\controllino-server\node_modules\@grpc\grpc-js\build\src\call-stream.js:145:78
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Caused by: Error
at CollectionReference._get (C:\Users\simeon.ramjit\Documents\projects\controllino-server\node_modules\@google-cloud\firestore\build\src\reference.js:1450:23)
at CollectionReference.get (C:\Users\simeon.ramjit\Documents\projects\controllino-server\node_modules\@google-cloud\firestore\build\src\reference.js:1439:21)
at Object.<anonymous> (C:\Users\simeon.ramjit\Documents\projects\controllino-server\index.js:41:57)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
code: 14,
details: 'No connection established',
metadata: Metadata { internalRepr: Map(0) {}, options: {} }
}
Upvotes: 5
Views: 12937
Reputation: 1216
This issue can also be caused by firebase application not able to resolve domain names. On ubuntu, I had switched to using ufw using /etc/docker/daemon.json file as follows:
{
"iptables":false
}
This blocks docker from using default outgoing rules available in the iptables. Several options can be used with ufw to enable outgoing traffic eg.
ufw allow ssh
ufw default allow outgoing
ufw enable
You can also enable outgoing to specific IP addresses as needed. More on these instructions can be found here
Upvotes: 1
Reputation: 1748
As mentioned above if the FIRESTORE_EMULATOR_HOST environment variable is set the admin SDK will try to connect to your emulator.
Following this comment I deleted the env variable and restarted my terminal and it connected to production successfully
Upvotes: 8