Firestore 按对象键查询

Jm3*_*m3s 6 javascript firebase angular google-cloud-firestore

我在 firestore 的集合中有一系列嵌套对象,它们有一个 UID 的键。我想通过检查他们的 UID 是否是对象键(基本上如果它存在)来查询与用户相关的所有文档。这是firestore中的模型: 在此处输入图片说明

这就是我目前尝试返回文件的方式:

  getAllTenancyOffersByUserId() {
    return this.afs.collection('collection_name', ref =>
      ref.where(`application.members.${this._auth.currentUserId}`, '==', !null),
    );
  }
Run Code Online (Sandbox Code Playgroud)

但这没有任何回报。我知道我可以通过该状态进行查询,但是它会不断更新,因此会导致问题

Ren*_*nec 5

以下应该可以解决问题:

  getAllTenancyOffersByUserId() {
    return this.afs.collection('members', ref =>
      ref.where(firebase.firestore.FieldPath.documentId(), '==', `${this._auth.currentUserId}`)
    );
  }
Run Code Online (Sandbox Code Playgroud)

请参阅相应的文档:https : //firebase.google.com/docs/reference/js/firebase.firestore.FieldPath#.documentId


ctw*_*ome 5

实际上,您可以做的是按对象中的任何字符串字段进行过滤,如下所示:

.collection("collectionName")
.where("mapArray.map.stringField", ">", "''")
Run Code Online (Sandbox Code Playgroud)

这里重要的部分是字符串字段;">"、"''"