为什么Firestore会查询我的所有引用?

时间:2018-11-26 09:09:48

标签: javascript firebase google-cloud-firestore

最近,当我启用OfflinePersistence时,我注意到保存了太多文档。我想知道为什么并激活了日志级别的“调试”,以便分析我查询少量文档时发生的情况。

为了给您背景知识,我的数据库如下所示:

{
  recurrences: {
    day: integer
    slots: array of references to documents of slots
    [...]
  }
  slots: {
    date: date
    recurrence: reference to a document of recurrences
    [...]
  }
}

我的查询收集日期范围内的所有广告位:

this.$firestore.collection('slots')
        .where('start', '>=', moment(currentWeek).toDate())
        .where('start', '<', moment(currentWeek).add(7, 'days').toDate())

但是,因为每个Slot文档都有对重复文档的引用,所以正如我在日志中看到的那样,Firestore似乎直接查询相应的重复文档:

[2018-11-26T08:54:00.129Z]  @firebase/firestore: Firestore (5.5.0) [Connection]: WebChannel received: {"documentChange":{"document":{"name":"projects/projet/databases/(default)/documents/slots/ARnClPDr03bHI6ZI5V5","fields":{"start":{"timestampValue":"2018-12-01T16:00:00Z"},"status":{"stringValue":"RESTRICTED"},"participants_count":{"integerValue":"0"},"recurrence":{"referenceValue":"projects/projet/databases/(default)/documents/recurrences/31shOUDlY9Sq3COthxSu"},"duration":{"integerValue":"1"},"participants":{"mapValue":{}},"title":{"stringValue":"ville"}},"createTime":"2018-11-25T21:27:24.844292Z","updateTime":"2018-11-25T21:27:56.743319Z"},"targetIds":[4]}}
[...]
 [2018-11-26T08:54:00.207Z]  @firebase/firestore: Firestore (5.5.0) [Connection]: WebChannel sending: {"database":"projects/projet/databases/(default)","addTarget":{"documents":{"documents":["projects/projet/databases/(default)/documents/recurrences/H2NLe394D6heR0Zs178o"]},"targetId":6}}

可以在此处找到更多日志:https://pastebin.com/V5rpq6Ya

由于重复文档存储了很多Slot参考,Firestore继续查询所有相关的Slot文档...

要恢复,一个应该向我返回一些结果的小查询将返回整个数据库。

如何告诉Firestore保持浅层状态并且不查询参考文档?

预先感谢您:)

0 个答案:

没有答案
相关问题