ReallySmallSoftware/cordova-plugin-firestore

Firestore collection object isn't working right

Opened this issue · 7 comments

Expected Behavior

Adding a record should work.

var options = {
  "datePrefix": '__DATE:',
  "fieldValueDelete": "__DELETE",
  "fieldValueServerTimestamp" : "__SERVERTIMESTAMP",
  "persist": true,
  "config" : {}
};
Firestore.initialise(options).then(function(db) { window.db = db; })
window.db.collection('test').add({ "test": "value" }).then(console.log).catch(console.error);

Actual Behavior

Throws error:

Attempt to invoke virtual method 'com.google.firebase.firestore.CollectionReference com.google.firebase.firestore.FirebaseFirestore.collection(java.lang.String)' on a null object reference

Steps to Reproduce the Problem

Using in chromium debug window attached to cordova webview instance on a phone. I've installed the plugins without issue.

Specifications

  • Plugin version: 1.3.2
  • Framework: cordova / framework7
  • Framework version:
  • Operating system: Antergos linux/ android

note that creating the collection object works fine, this error appears on both 'add' and 'get' functions.

var c = window.db.collection('contacts');
c.get('A').then(console.log); // record 'A' exists on firebase.

I have this working using the javascript API, but having issues with the web ui for auth, so wanted to use your nice firebaseui plugin which works great!

Thanks for any help.

Taking your first example, is the code structured exactly like that? Are you sure the promise has been satisfied before it gets to the add line?

For testing purposes could you try this?

Firestore.initialise(options).then(function(db) {
window.db = db;
window.db.collection('test').add({ "test": "value" }).then(console.log).catch(console.error);
})

The promise seems to return resolved right away - but I'll try that, it's good to be sure of that obviously.

I appreciate your help! I'll try it first thing in the morning and close this out and kick myself it that's all it was.

Hi ,
I am also facing the same issue. I created a sample project using the procedure given in the plugin page. After some debugging I found that "firestorePlugin.getDatabase()" returns null on "DocSetHandler.java" . I will try to debug more and share that info soon.

var options = {
"datePrefix": '__DATE:',
"fieldValueDelete": "__DELETE",
"fieldValueServerTimestamp" : "__SERVERTIMESTAMP",
"persist": true,
"config" : {}
};

For Android/IoS applications , "config" key should not be present in the "options" JSON. If it is present code assumes it to be a web applications and works accordingly . After removing this key , app works fine.

I believe the example may be wrong. Try this:

window.db.get().collection('test').add({ "test": "value" }).then(console.log).catch(console.error);

In add, as per comment above, "config" : {} needs to be comment out.
Then it works both for Android and browser platform (iOS to be tested)