firebase - 带有颤动的timetemp的Firestore查询
问题描述
我正在像这样向我的收藏中添加一个文档。
void addToDb() {
collectionReference.add({
'dateTime': FieldValue.serverTimestamp(),
});}
我正在尝试像这样在某个日期时间之后查询数据
Firestore.instance
.collection('items')
.orderBy('dateTime', descending: true).startAt([{'dateTime' : DateTime.parse('2019-03-13 16:49:42.044')}])
.snapshots(),
当我将descending 设置为true 时,我会取回所有文档。当我设置为假时,我什么也没回来。两者都不是预期的结果。
我在堆栈上看到一些说将日期时间转换为毫秒或 unix。但我正在使用 servertimestamp 因为我不能信任客户端写时间戳。知道如何使用 servertimestamp 查询日期时间范围吗?
解决方案
我无法真正解释为什么会这样,但这对我有用。
final startAtTimestamp = Timestamp.fromMillisecondsSinceEpoch(DateTime.parse('2019-03-13 16:49:42.044').millisecondsSinceEpoch);
Firestore.instance
.collection('items')
.orderBy('dateTime', descending: true).startAt([startAtTimestamp])
.snapshots()
推荐阅读
- libreoffice - 当我选择表格 [Libreoffice] 时,无法点击 PDF 导出时的目录链接
- python - matplotlib 中的逐步线图
- docker - 什么是“清单 blob 未知:注册表未知的 blob”错误
- python - (没有名为 __main__ 的模块)在 bashrc 中使用别名时
- c++ - C++ 警告:并非所有控制路径都返回值
- c++ - * function() 和 function() 的区别
- postgresql - Postgres函数错误:未终止的美元报价
- php - $_GET 值到 if else 语句中
- oracle - 如何在两个 Oracle RDS 实例之间创建数据库链接
- bash - Bash:printf中特殊字符的文字字符串