EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 444 forks source link

Sample with RealDB and Firestore in the same app #561

Closed d3mac123 closed 6 years ago

d3mac123 commented 6 years ago

I am trying to play with Firestore in my current (Realtime DB) app. Here's what I have:

var firebase = require("nativescript-plugin-firebase");

firebase.init({
    url: "https://name-of-the-app.firebaseio.com/",
    persist: true,
    storageBucket: 'gs://name-of-the-app.appspot.com'

}).then(
    function (instance) {
        console.log("firebase.init done");
    },
    function (error) {
        console.log("firebase.init error: " + error);
    }
);

Trying to run the sample Firestore code:

var placesCollection = firebase.firestore().collection("places");
console.log(placesCollection)
placesCollection.get().then(querySnapshot => {
    querySnapshot.forEach(doc => {
      console.log(`${doc.id} => ${JSON.stringify(doc.data())}`);
    });
  });

I get the following error:

1   0x10c417bc8 -[TNSRuntime executeModule:referredBy:]
2   0x1098ecf01 main
3   0x110177d81 start
4   0x1
file:///app/app.js:109:42: JS ERROR TypeError: firebase.firestore is not a function. (In 'firebase.firestore()', 'firebase.firestore' is an instance of Object)

Which I assume is because the Firestore database needs to be referenced (after all, its name is just name-of-the-app, instead of https://name-of-the-app.firebaseio.com/

How can I do that?

EddyVerbruggen commented 6 years ago

Check demo-ng in this repo for a mixed db demo 👍

d3mac123 commented 6 years ago

I guess I am screwed :) Never worked with Angular and the code there seems to be "a bit" unreadable for a designer fighting with Vanilla JS code.

I will keep "fighting" here. Looking forward to reading an updated Docs in plain JS.

EddyVerbruggen commented 6 years ago

Ehm, I’m on my phone in a car so it’s hard to help, but go here and look at the const firebase at the top: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/demo-ng/app/item/items.component.ts — that one has the firestore() function.

EddyVerbruggen commented 6 years ago

Same as in the readme actually: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/FIRESTORE.md

Just make sure you have that /app at the end of the require.

d3mac123 commented 6 years ago

the /app needs to be the "app-name" or just the word app, as in the docs?

EddyVerbruggen commented 6 years ago

/app as in the docs. It’s a physical folder in the plugin source.