Reputation: 465
I have created a new Realtime Database in the same project.
I followed the instructions here but got some errors.
final db = FirebaseDatabase.instance.ref(); // default database instance
// using ref()
final db2 = FirebaseDatabase.instance.ref('https://mydb2.us-central1.firebasedatabase.app');
// error Invalid Firebase Database path
// Firebase Database paths must not contain '.', '#', '$', '[', or ']'
// using refFromURL()
final db3 = FirebaseDatabase.instance.refFromURL('https://mydb2.us-central1.firebasedatabase.app');
// error Invalid argument (must equal the current FirebaseDatabase instance databaseURL)
Same goes if using
.firebaseio.com
in the URL.
So what is the correct way to get DatabaseReference for secondary database in the same project?
Upvotes: 3
Views: 1212
Reputation: 465
I've figured out by using instanceFor()
:
final db2 = FirebaseDatabase.instanceFor(
app: Firebase.app(),
databaseURL: 'https://mydb2.us-central1.firebasedatabase.app/'
).ref();
Upvotes: 4