For console output from the firestore
call, I am getting No such document!
, even though there is a document there (I can see it in the firebase console). Here are some screenshots showing my firestore
database:
Here is my code:
var db = firebase.firestore();
// Disable deprecated features
db.settings({
timestampsInSnapshots: true
});
console.log("app.selectedPoolId:", app.selectedPoolId);
db.collection("pools").doc(app.selectedPoolId).collection("items").doc("items_array").get()
.then(function(doc) {
if (doc.exists) {
...
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
CONSOLE OUTPUT
app.selectedPoolId: Eamon's pool
This happens when I try to run my hybrid ios/phonegap
app from XCode
on a device. What am I missing?
UPDATE
I output the doc
object's keys and values, just incase anyone notices anything weird.
This code:
for (var prop in doc) {
console.log("doc key:", prop);
console.log("doc value:", doc[prop]);
}
Produces this output:
2019-02-07 16:05:21.306952-0500 HybridPool[5063:1305478] app.selectedPoolId: Eamon's pool
2019-02-07 16:05:21.524750-0500 HybridPool[5063:1305478] doc key: _firestore
2019-02-07 16:05:21.524868-0500 HybridPool[5063:1305478] doc value: [object Object]
2019-02-07 16:05:21.524987-0500 HybridPool[5063:1305478] doc key: _key
2019-02-07 16:05:21.525044-0500 HybridPool[5063:1305478] doc value: pools/Eamon's pool/items/items_array
2019-02-07 16:05:21.525095-0500 HybridPool[5063:1305478] doc key: _document
2019-02-07 16:05:21.525133-0500 HybridPool[5063:1305478] doc value:
2019-02-07 16:05:21.525171-0500 HybridPool[5063:1305478] doc key: _fromCache
2019-02-07 16:05:21.525208-0500 HybridPool[5063:1305478] doc value: false
2019-02-07 16:05:21.525274-0500 HybridPool[5063:1305478] doc key: _hasPendingWrites
2019-02-07 16:05:21.525388-0500 HybridPool[5063:1305478] doc value: false
2019-02-07 16:05:21.525435-0500 HybridPool[5063:1305478] doc key: data
2019-02-07 16:05:21.525512-0500 HybridPool[5063:1305478] doc value: function (t){return mr("DocumentSnapshot.data",arguments,0,1),t=lc("DocumentSnapshot.data",t),this._document?this.convertObject(this._document.data,ri.fromSnapshotOptions(t,this._firestore._areTimestampsInSnapshotsEnabled())):void 0}
2019-02-07 16:05:21.525561-0500 HybridPool[5063:1305478] doc key: get
2019-02-07 16:05:21.525624-0500 HybridPool[5063:1305478] doc value: function (t,e){if(mr("DocumentSnapshot.get",arguments,1,2),e=lc("DocumentSnapshot.get",e),this._document){var n=this._document.data.field(ju("DocumentSnapshot.get",t));if(void 0!==n)return this.convertValue(n,ri.fromSnapshotOptions(e,this._firestore._areTimestampsInSnapshotsEnabled()))}}
2019-02-07 16:05:21.525672-0500 HybridPool[5063:1305478] doc key: id
2019-02-07 16:05:21.525711-0500 HybridPool[5063:1305478] doc value: items_array
2019-02-07 16:05:21.525749-0500 HybridPool[5063:1305478] doc key: ref
2019-02-07 16:05:21.525818-0500 HybridPool[5063:1305478] doc value: [object Object]
2019-02-07 16:05:21.525857-0500 HybridPool[5063:1305478] doc key: exists
2019-02-07 16:05:21.525895-0500 HybridPool[5063:1305478] doc value: false
2019-02-07 16:05:21.525933-0500 HybridPool[5063:1305478] doc key: metadata
2019-02-07 16:05:21.525971-0500 HybridPool[5063:1305478] doc value: [object Object]
2019-02-07 16:05:21.526008-0500 HybridPool[5063:1305478] doc key: isEqual
2019-02-07 16:05:21.526232-0500 HybridPool[5063:1305478] doc value: function (e){if(!(e instanceof t))throw Nr("isEqual","DocumentSnapshot",1,e);return this._firestore===e._firestore&&this._fromCache===e._fromCache&&this._key.isEqual(e._key)&&(null===this._document?null===e._document:this._document.isEqual(e._document))}
2019-02-07 16:05:21.526289-0500 HybridPool[5063:1305478] doc key: convertObject
2019-02-07 16:05:21.526329-0500 HybridPool[5063:1305478] doc value: function (t,e){var n=this,r={};return t.forEach(function(t,i){r[t]=n.convertValue(i,e)}),r}
2019-02-07 16:05:21.526429-0500 HybridPool[5063:1305478] doc key: convertValue
2019-02-07 16:05:21.526496-0500 HybridPool[5063:1305478] doc value: function (t,e){if(t instanceof gi)return this.convertObject(t,e);if(t instanceof vi)return this.convertArray(t,e);if(t instanceof mi){var n=t.value(e),r=this._firestore.ensureClientConfigured().databaseId();return t.databaseId.isEqual(r)||$n("Document "+this._key.path+" contains a document reference within a different database ("+t.databaseId.projectId+"/"+t.databaseId.database+") which is not supported. It will be treated as a reference in the current database ("+r.projectId+"/"+r.database+") instead."),new rc(n,this._firestore)}return t.value(e)}
2019-02-07 16:05:21.526629-0500 HybridPool[5063:1305478] doc key: convertArray
2019-02-07 16:05:21.526713-0500 HybridPool[5063:1305478] doc value: function (t,e){var n=this;return t.internalValue.map(function(t){return n.convertValue(t,e)})}
UPDATE
I realized I could get the same document using where
on it's collection
, but when I try that - it acts as if the function never executes - no error messages, or any other kind of message - it stops after:
console.log("app.selectedPoolId:", app.selectedPoolId);
It outputs the same thing because of the above line, and then stops running without any errors, this is the code I am running to query the collection:
db.collection("pools").where("name", "==", app.selectedPoolId).get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
console.error("Error writing document: ", error);
});
Again, no output results form the above code.
Here are the firestore
best practices - I looked through them and I think my code complies:
I am not sure on this but the problem may be that the document name "Eamon's pool" has a space in it and so it not recognizing the whole thing or it is stopping at the first part of the string "Eamon's".
In the past, when I have used Firestore, the document names I have used contain no spaces and so having space could be the problem.
Try renaming the document to EamonsPool or a name with no space and try again.