-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Firestore] Can not connect to both production and local emulator database #1839
Comments
I found a few problems with this issue:
|
So it seems that THE ONLY WAY to connect to a local firestore database is by setting the environment variable. I tried this and, indeed it connected to the local database, what I can not be sure about is I am able to connect to both at the same time. It will be nice if docs were more clear about this, and it will be awesome if you allow to just pass that as a configuration option in the initialize app config object |
You can probably set the emulator environment variable in the code and remove once you initialize the production app. process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080';
const localApp = initializeApp(
{ projectId: 'test-project', databaseURL: `localhost:${emulators.firestore.port}` },
'local',
);
delete process.env.FIRESTORE_EMULATOR_HOST; In the future, please use StackOverflow for usage questions. |
I'm trying to do this as well, and I think it's a perfectly reasonable feature request to not have to depend on env vars to accomplish this. It's just not very clean to have to add and remove env vars on a temporary basis when an API would be better. There should be some options to pass to |
Hi @CodingDoug , Thank you for suggesting this. There are different products in Firebase and you get the choices to use some of it against emulator and others against production. So it is not easy to add simple options on this top level function However, you can do something like the following to bypass environment variables: const admin = require('firebase-admin');
admin.initializeApp();
const firestore = admin.firestore();
firestore.settings({
...firestore.settings,
host: 'localhost:8080',
ssl: false
}); |
@cherylEnkidu Wouldn't it be possible to introduce a new function to initialize the app against the emulator alone? I don't really need to single out one product for use with the emulator. What I want is two initialized apps, one against the project and another against the emulator, so that I can have an easier time copying data between them using more than one product. Right now I'm doing this:
It seems unnecessarily complex when I could instead just use a different initializer function for the emulator-only instance. |
Hi @CodingDoug , Can you open a new issue, label |
@cherylEnkidu Added here: #2327 |
[REQUIRED] Step 1
Yes, I think this is the right place
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
Please take a look at the attached code in the next section.
When you try to run that code you will get an error saying that
TypeError: this.ensureApp(...).firestore is not a function
. Seems that the initializeApp method is not returning an actual app instance that includes everything.I want to be able to connect both to my production app and to my local emulator suite so I can do some dumps from one to the other.
This will print Firestore logs to the console.
Relevant Code:
The text was updated successfully, but these errors were encountered: