如何在Firestore中查询DocumentReference

问题描述 投票:6回答:1

我有一个酒吧命令的集合,并且在每个文档中都有一个带有酒保参考的字段。

Illustrative image


我正在尝试使用文档参考信息。

类似的东西:

orders = this.database.collection("orders",
    (ref) => ref.where("barman.path", "==", "barmen/" + this.auth.auth.currentUser.uid),
);
return orders.valueChanges();

barman.path,因为当我获得带有字段引用的文档时,这是获取引用路径的方法。

我已经尝试只使用barman代替barman.path

我已经尝试使用docref(firestore.googleapis.com/pro...)的完整'path'进行定位。

有什么想法吗?

仅输入ID而不是完整引用将使系统的其他部分困难。

javascript angular firebase google-cloud-firestore angularfire2
1个回答
0
投票

为了查询参考字段,您应该创建一个与您要查询的位置相匹配的DocumentReference对象,并使用该对象。请注意,这需要是本地Firestore引用,因为AngularFirestoreCollectionAngularFirestoreDocument只会在Firestore中显示为“自定义对象类型”。您可以使用AngularFirestore类型的ref成员来获得它。

我不确定查询的'.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();

我显然无法完全测试此代码,因为没有足够的代码来证明this.auth.auth.currentUser.uid在这种情况下有效。但这应该为您指明正确的方向。

© www.soinside.com 2019 - 2024. All rights reserved.