- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
'>=' 或 '=', t-6ren">
我正在按时间戳查询文档,它返回一个空数组。但是,当我使用 "==" ex:.where('date', '==',timestamp) 时它有效,并且当我使用 时返回空数组>'>=' 或 '<='。
我也尝试过将时间戳转换为日期对象和字符串,但没有成功。
注意:firestore 中的date 字段是Timestamp 类型。
我正在查询集合中日期大于“2018-08-03”的文档。
下面是交易集合(左)和文档(右)的图片,它们应该是返回文档数组的一部分,因为日期大于“2018-08-03”
下面是我的代码。
const firstDay = new Date('2018-08-03');
const timestamp1 = admin.firestore.Timestamp.fromDate(firstDay);
const trans = [];
const docRef = db.collection('Users').doc(uid).collection('transactions').where('item_id', '==', item_id)
.where('date', '>=', timestamp1);
await docRef.get()
.then((snapshot) => {
snapshot.forEach((doc) => {
trans.push({ transaction_id: doc.id, transaction: doc.data() });
});
})
.catch(err => new Error('cannot get the documents', err));
预期结果:应该是一个包含日期大于上述指定日期的交易的数组。
实际结果:空数组。
由于它致力于平等==,我假设>= 和<= 会起作用。我在这里遗漏了什么吗?
Logs after trying ">" (equal to timestamp1)
Firestore (2.3.0) 2019-10-03T14:01:25.013Z AObRG [ClientPool.acquire]: Re-using existing client with 100 remaining operations
Firestore (2.3.0) 2019-10-03T14:01:25.015Z AObRG [Firestore.readStream]: Sending request: {"parent":"projects/valuemo-000/databases/(default)/documents/Users/Xmr3vKT19OSST02DSTDMt0jSq692","structuredQuery":{"from":[{"collectionId":"transactions"}],"where":{"compositeFilter":{"op":"AND","filters":[{"fieldFilter":{"field":{"fieldPath":"item_id"},"op":"EQUAL","value":{"stringValue":"zGRkpP3QkzI89zKyDjZ7FPDrXd5G3Bco5ENlR"}}},{"fieldFilter":{"field":{"fieldPath":"date"},"op":"EQUAL","value":{"timestampValue":{"seconds":1533254400}}}}]}}}}
Firestore (2.3.0) 2019-10-03T14:01:25.232Z AObRG [Firestore._initializeStream]: Received stream error: { Error: The query requires a COLLECTION_ASC index
for collection transactions and field date. That index is not ready yet. See its status here: https://console.firebase.google.com/project/valuemo-000/database/firestore/indexes/single_field?create_exemption=ClJwcm9qZWN0cy92YWx1ZW1vLTAwMC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvdHJhbnNhY3Rpb25zL2ZpZWxkcy9kYXRlEAEaCAoEZGF0ZRAB
at Http2CallStream.call.on (D:\Projects\Valuemo-firebase\node_modules\@grpc\grpc-js\build\src\call.js:68:41)
at Http2CallStream.emit (events.js:194:15)
at process.nextTick (D:\Projects\Valuemo-firebase\node_modules\@grpc\grpc-js\build\src\call-stream.js:71:22)
at process.internalTickCallback (internal/process/next_tick.js:70:11)
code: 9,
details:
'The query requires a COLLECTION_ASC index for collection transactions and field date. That index is not ready yet. See its status here: https://console.firebase.google.com/project/valuemo-000/database/firestore/indexes/single_field?create_exemption=ClJwcm9qZWN0cy92YWx1ZW1vLTAwMC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvdHJhbnNhY3Rpb25zL2ZpZWxkcy9kYXRlEAEaCAoEZGF0ZRAB',
metadata: Metadata { options: undefined, internalRepr: Map {} } }
Firestore (2.3.0) 2019-10-03T14:01:25.256Z AObRG [Firestore._initializeStream]: Received initial error: { Error: The query requires a COLLECTION_ASC index for collection transactions and field date. That index is not ready yet. See its status here: https://console.firebase.google.com/project/valuemo-000/database/firestore/indexes/single_field?create_exemption=ClJwcm9qZWN0cy92YWx1ZW1vLTAwMC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvdHJhbnNhY3Rpb25zL2ZpZWxkcy9kYXRlEAEaCAoEZGF0ZRAB
at Http2CallStream.call.on (D:\Projects\Valuemo-firebase\node_modules\@grpc\grpc-js\build\src\call.js:68:41)
at Http2CallStream.emit (events.js:194:15)
at process.nextTick (D:\Projects\Valuemo-firebase\node_modules\@grpc\grpc-js\build\src\call-stream.js:71:22)
at process.internalTickCallback (internal/process/next_tick.js:70:11)
code: 9,
details:
'The query requires a COLLECTION_ASC index for collection transactions and field date. That index is not ready yet. See its status here: https://console.firebase.google.com/project/valuemo-000/database/firestore/indexes/single_field?create_exemption=ClJwcm9qZWN0cy92YWx1ZW1vLTAwMC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvdHJhbnNhY3Rpb25zL2ZpZWxkcy9kYXRlEAEaCAoEZGF0ZRAB',
metadata: Metadata { options: undefined, internalRepr: Map {} } }
Firestore (2.3.0) 2019-10-03T14:01:25.260Z AObRG [Firestore._retry]: Request failed with unrecoverable error: { Error: The query requires a COLLECTION_ASC index for collection transactions and field date. That index is not ready yet. See its status here: https://console.firebase.google.com/project/valuemo-000/database/firestore/indexes/single_field?create_exemption=ClJwcm9qZWN0cy92YWx1ZW1vLTAwMC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvdHJhbnNhY3Rpb25zL2ZpZWxkcy9kYXRlEAEaCAoEZGF0ZRAB
at Http2CallStream.call.on (D:\Projects\Valuemo-firebase\node_modules\@grpc\grpc-js\build\src\call.js:68:41)
at Http2CallStream.emit (events.js:194:15)
at process.nextTick (D:\Projects\Valuemo-firebase\node_modules\@grpc\grpc-js\build\src\call-stream.js:71:22)
at process.internalTickCallback (internal/process/next_tick.js:70:11)
code: 9,
details:
'The query requires a COLLECTION_ASC index for collection transactions and field date. That index is not ready yet. See its status here: https://console.firebase.google.com/project/valuemo-000/database/firestore/indexes/single_field?create_exemption=ClJwcm9qZWN0cy92YWx1ZW1vLTAwMC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvdHJhbnNhY3Rpb25zL2ZpZWxkcy9kYXRlEAEaCAoEZGF0ZRAB',
metadata: Metadata { options: undefined, internalRepr: Map {} } }
最佳答案
所以我正在测试它,我认为它与您展示的设置非常相似,而且我实际上能够重现相同的行为。
在测试了各种可能性后,我发现我的问题与字段的数据类型无关,而是与复合索引的配置有关。
执行此查询所需的复合索引配置如下:
根据Queries supported by composite indexes在文档的部分,这些类型的复合查询的索引应该首先具有相等过滤字段,这没有明确说明,但文档在示例中就是这样呈现的。
如果这能为您解决问题,请告诉我。
关于javascript - 按时间戳查询 firestore 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58106160/
给定一个带有多个 date_time 戳的字符串,我想 提取第一个戳及其前面的文本 候选字符串可以有一个或多个时间戳 后续的 date_time 戳记将被 sep="-" 隔开 后续date_time
是否可以合并从相机拍摄的文本和照片?我想在照片上标记日期和时间,但我在 Google 上找不到任何内容。 最佳答案 使用下面的代码来实现你所需要的。 Bitmap src = Bitm
有没有办法通过 Graph API 戳另一个用户?基于this post ,并使用 Graph Explorer ,我发布到“/USERID/pokes”,我已经授予它(Graph API 应用程序和
我有两个向左浮动的元素。一个是 body 的第一个 child ,另一个是容器的第一个 child ,容器是 body 的第二个 child 。 ...
我是一名优秀的程序员,十分优秀!