这是我的代码。现在,我只是想确保我知道如何格式化日期以获取日期。我已经尝试了Month-date-year,但似乎没有用。我能够获得Firestore通过它的对象,如下所示。
{
客户注意事项:“ Quisque malesuada sagittisposuere。Vestibulumleo enim,aliquam ut fermentum id,
欧洲前庭。 Maecenas ornare ultrices dui ne facilisis。 Vivamus convallis eros at
应用日期:时间戳
纳秒:0
秒:1577336400
}
firebase
.firestore()
.collection("appointments")
.where("UserId", "==", user.uid)
.where("Date_of_Appt", "==", "1577336400")
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
this.setState({
uid: user.uid
});
};
答案 0 :(得分:1)
您现在正在传递Date_of_Appt
的字符串值。由于您将Date_of_Appt
作为Timestamp
对象存储在数据库中,因此将其与字符串进行比较将永远不会与文档匹配。
传递JavaScript Date
对象或Firestore Timestamp
对象的解决方案。由于您似乎将时间间隔定为秒,因此最简单的是这样的时间戳:
firebase
.firestore()
.collection("appointments")
.where("UserId", "==", user.uid)
.where("Date_of_Appt", "==", new firebase.firestore.Timestamp(1577336400,0))
.get()
以上内容仅返回与您传递的时间戳值完全匹配的文档。如果您要返回范围内带有Date_of_Appt
的文档,则需要使用>=
和<=
。