说我有这个文件
userProfile: {
createdAt: '2018-01-01',
updatedAt: '2018-01-04'
}
我想要检索创建后更新的所有userProfiles
,这意味着满足createdAt < updatedAt
的那些。
你能在Firestore做到吗?
像这样的东西,但第二个操作数是一个字段,而不是一个值:
userProfileRef.where("createdAt", "<", "updatedAt")
谢谢
您将无法使用“标准”Firestore查询执行此操作。
最简单的方法是:
updatedAt
字段中具有默认的“虚拟”日期(例如1900-01-01)。然后,您将使用userProfileRef.where("updatedAt", ">", "1900-01-01")
进行查询要么
updatedAt
字段的值时(即在创建后更新文档时),您将更新文档中的特定标志。请注意,您无法查询不包含给定字段的文档(请查看此官方video以获取更多详细信息),因此您不能依赖缺少updatedAt
字段。