Jos*_*tas 6 javascript firebase angularfire2 angular google-cloud-firestore
我有一个条形码的集合,并在每个文件中我有一个字段与酒保的参考.
我正试图在doc引用的位置.
像这样的东西:
orders = this.database.collection("orders",
(ref) => ref.where("barman.path", "==", "barmen/" + this.auth.auth.currentUser.uid),
);
return orders.valueChanges();
Run Code Online (Sandbox Code Playgroud)
barman.path 因为当我得到一个带有字段引用的文档时,这是获取引用路径的方法.
我已经尝试过只使用barman代替barman.path.
我已经尝试用docref(firestore.googleapis.com/pro...)的完整"路径"来制作.
有任何想法吗?
只放入id而不是完整的引用会使系统的其他部分变得困难.
为了查询引用字段,您应该创建一个DocumentReference与您尝试查询的位置匹配的对象并使用它。请注意,这需要是本机 Firestore 引用,并且AngularFirestoreCollection只会AngularFirestoreDocument作为“自定义对象类型”显示在 Firestore 中。ref您可以通过AngularFirestore 类型的成员来获取它。
我不确定查询的“.path”部分来自哪里,因为您查询的实际字段是barman。我已经在示例中删除了它。
在你的情况下,这看起来像:
const queryReference = this.database
.collection('barmen')
.doc(this.auth.auth.currentUser.uid).ref;
orders = this.database.collection('orders',
(ref) => ref.where('barman', '==', queryReference),
);
return orders.valueChanges();
Run Code Online (Sandbox Code Playgroud)
显然,我无法准确地测试这一点,因为没有足够的代码来证明this.auth.auth.currentUser.uid在这种情况下有效。但它应该为您指明正确的方向。
| 归档时间: |
|
| 查看次数: |
360 次 |
| 最近记录: |