用于控制台输出
firestore
打电话给我
No such document!
即使那里有文档(我可以在FireBase控制台中看到)。以下是一些显示我的
火店
数据库:
这是我的代码:
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);
});
控制台输出
app.selectedPoolId: Eamon's pool
当我试着运行我的混合动力车时就会发生这种情况
ios/phonegap
应用程序从
XCode
在一个装置上。我错过了什么?
更新
我输出
doc
对象的键和值,只是为了防止任何人发现任何奇怪的东西。
此代码:
for (var prop in doc) {
console.log("doc key:", prop);
console.log("doc value:", doc[prop]);
}
生成此输出:
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)})}
更新
我意识到我可以用
where
在它的
collection
,但当我尝试时-它的作用就像函数从未执行-没有错误消息或任何其他类型的消息-它在以下时间后停止:
console.log("app.selectedPoolId:", app.selectedPoolId);
由于上面的行,它输出相同的内容,然后停止运行而不出现任何错误,这是我运行以查询集合的代码:
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);
});
同样,上面的代码没有输出结果。
这里是
火店
最佳实践-我查看了它们,我认为我的代码符合:
Firestore Best Practices