ReallySmallSoftware / cordova-plugin-firestore

A Google Firebase Firestore plugin to enable realtime synchronisation between app and cloud and automatically handle limited connectivity.
Other
22 stars 10 forks source link

Firestore collection object isn't working right #11

Open MicahStevens opened 5 years ago

MicahStevens commented 5 years ago

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

MicahStevens commented 5 years ago

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.

ReallySmallSoftware commented 5 years ago

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); })

MicahStevens commented 5 years ago

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.

wbcbharani commented 5 years ago

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.

wbcbharani commented 5 years ago

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.

ReallySmallSoftware commented 5 years ago

I believe the example may be wrong. Try this:

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

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)