Javascript: Can't get a secondary database instance by URL

670 views
Skip to first unread message

Michael

unread,
Feb 26, 2018, 4:40:33 PM2/26/18
to Firebase Google Group
Trying to connect to a second database instance by URL but keep getting an error.

Code: (Copied directly from the docs)

var database = firebase.database('https://MY-FIREBASE.firebaseio.com');


returns an error of:


vendors.js:150 database: Firebase: firebase.database() takes either no argument or a Firebase App instance. (app/invalid-app-argument).


Using the latest version:


/*!

 * @license Firebase v4.9.1

 * Build: rev-631e1ad

 * Terms: https://firebase.google.com/terms/

 */


Any ideas? 

Kato Richardson

unread,
Feb 27, 2018, 11:34:52 AM2/27/18
to Firebase Google Group
Hey Michael,

Looking into this. I was able to repro.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/7a48363e-134e-467a-9947-6a762be7ee09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Michael

unread,
Feb 27, 2018, 3:42:42 PM2/27/18
to Firebase Google Group

Thanks Kato.

Also having the same type of issue with functions:

const functions = require('firebase-functions');
const firebase = require('firebase-admin');

firebase.initializeApp(functions.config().firebase);

const DB = firebase.database("<database-name>");

firebase deploy --only functions    Returns an error message:

TypeError: ns.ensureApp(...).database is not a function




On Tuesday, February 27, 2018 at 11:34:52 AM UTC-5, Kato Richardson wrote:
Hey Michael,

Looking into this. I was able to repro.

☼, Kato
On Mon, Feb 26, 2018 at 2:40 PM, Michael <mi...@quickhuddle.com> wrote:
Trying to connect to a second database instance by URL but keep getting an error.

Code: (Copied directly from the docs)

var database = firebase.database('https://MY-FIREBASE.firebaseio.com');


returns an error of:


vendors.js:150 database: Firebase: firebase.database() takes either no argument or a Firebase App instance. (app/invalid-app-argument).


Using the latest version:


/*!

 * @license Firebase v4.9.1

 * Build: rev-631e1ad

 * Terms: https://firebase.google.com/terms/

 */


Any ideas? 

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/7a48363e-134e-467a-9947-6a762be7ee09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kato Richardson

unread,
Feb 27, 2018, 4:40:33 PM2/27/18
to Firebase Google Group
So it looks like we need to update our docs. Using firebase.database(<string>) isn't actually supported yet. Not sure why. I'll work on that.

For now, you can use an approach like this, where you just pass the app instance in rather than the string. 

It's fine to call initializeApp() multiple times with the same credentials, and just change out the DB URL. Note the second argument (a string naming the app instance).

☼, Kato

To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Michael

unread,
Feb 28, 2018, 12:52:05 AM2/28/18
to Firebase Google Group

Cool! That seems to work. Thanks for the quick response.


Found another possible error using multiple databases with functions.

Using this example of a function::

exports.testFunction= functions.database.instance(<datbase-name').ref('/test/{requestId}/').onCreate(event => {

the event.params is set to:

{
        requestId: undefined
}

If I run the same function using the default database it returns the correct value:

exports.testFunction= functions.database.ref('/test/{requestId}/').onCreate(event => {

the event.params is set to:

{
        requestId: -L6PuS5Mhpk1K0hkszE5
}

Any ideas? 

Kato Richardson

unread,
Feb 28, 2018, 11:37:45 AM2/28/18
to Firebase Google Group
Another great find. Would you mind submitting that one as a bug? Support can investigate and find a workaround, but will probably need to work with you a bit to repro the problem.

☼, Kato

To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

vik...@chotahospital.in

unread,
Jun 2, 2018, 7:40:32 PM6/2/18
to Firebase Google Group
Hi Kato, 

I am still facing the same problem as Michael. I have put the same question on stackoverflow as well. Any updates on support of firebase.database(<url>) implementation ?

FYI - Firebase version v5.0.4

Kato Richardson

unread,
Jun 4, 2018, 12:54:48 PM6/4/18
to Firebase Google Group
Use the app instance as I mentioned previously. Example here.


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages