Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore collection object isn't working right #11

Open
MicahStevens opened this issue Dec 21, 2018 · 7 comments
Open

Firestore collection object isn't working right #11

MicahStevens opened this issue Dec 21, 2018 · 7 comments

Comments

@MicahStevens
Copy link

MicahStevens commented Dec 21, 2018

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
@MicahStevens
Copy link
Author

MicahStevens commented Dec 21, 2018

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
Copy link
Owner

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
Copy link
Author

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
Copy link

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
Copy link

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
Copy link
Owner

I believe the example may be wrong. Try this:

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

@luigi37
Copy link

luigi37 commented Feb 26, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants