【发布时间】:2021-01-21 11:22:36
【问题描述】:
我想使用本地节点脚本在 Firestore 上执行临时请求:
const firebase = require("firebase");
require("firebase/firestore");
firebase.initializeApp({
apiKey: 'XXX',
authDomain: 'XXX',
projectId: 'XXX'
});
var db = firebase.firestore();
async function main() {
var startTime = Date.parse('2020-09-03T12:56:00.000+02:00') / 1000;
console.log('startTime = ', startTime)
const ordersRef = db.collection('orders');
const snapshot = await ordersRef
// .where('uuid', '==', 'b4543f28-11c9-4aa5-b7c1-fabd344d5e4a')
.where('created', '>=', startTime)
.get();
if (snapshot.empty) {
console.log('No matching documents.');
return;
}
snapshot.forEach(doc => {
console.log("%j", doc.data());
});
}
main()
.then(text => {
console.log('finished');
})
.catch(err => {
console.log('error');
});
当我使用条件.where('uuid', '==', 'b4543f28-11c9-4aa5-b7c1-fabd344d5e4a') 执行请求时,我得到了预期的响应:
➜ ~/Projects/firestore node adhoc.js
startTime = 1600356360
{"bid":"NhsrIsu8OLRqO80xfZmS","valid":true,"uuid":"b4543f28-11c9-4aa5-b7c1-fabd344d5e4a","created":{"seconds":1599130708,"nanoseconds":412000000}, ...}
finished
但是当我使用.where('created', '>=', startTime) 执行请求时(意思是:仅此 where 子句),它以某种方式失败(未找到文档),但我知道应该有多个结果..
➜ ~/Projects/firestore node adhoc.js
startTime = 1600356360
No matching documents.
finished
你能告诉我我做错了什么吗?谢谢!
[更新]
下面是时间戳值的截图:
【问题讨论】:
标签: firebase google-cloud-firestore