我正在按時間戳查詢文檔,它返回一個空數組。但是,當我使用"=="時它有效,例如:.where('date', '==',timestamp),并在我使用'>='或'<='時返回空數組。我也嘗試將時間戳轉換為日期對象和字符串,但沒有成功。注意:firestore 中的日期字段是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));預期結果:應該是一個交易日期大于上面指定的數組。實際結果:空數組。由于它為相等==工作,我認為>=和<=會工作。我在這里缺少什么嗎?
通過時間戳查詢firestore中的數據
瀟瀟雨雨
2021-10-29 13:58:36