Javascript Firestore通过查询基于时间的数据接收新数据
我想以一种可以更新新数据而忽略旧数据的方式构建数据。因此,我添加了一个时间字段,并考虑添加一个where子句和一个Javascript Firestore通过查询基于时间的数据接收新数据,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我想以一种可以更新新数据而忽略旧数据的方式构建数据。因此,我添加了一个时间字段,并考虑添加一个where子句和一个onSnapshot侦听器 创建集合的代码: const citiesRef = db.collection('cities'); await citiesRef.doc('SF').set({ createdDummyTime: new Date().toISOString(), //or just Date() name: 'San Francisco', popula
onSnapshot
侦听器
创建集合的代码:
const citiesRef = db.collection('cities');
await citiesRef.doc('SF').set({
createdDummyTime: new Date().toISOString(), //or just Date()
name: 'San Francisco', population: 860000,
});
集合更新的代码:
citiesRef
.doc('SF')
.update({
createdDummyTime: new Date().toISOString(),
name: 'San Francisco', population: 999999999,
}),
})
.then(() => {
console.log("res");
});
//or set another doc('blahblah') with time higher then querying with.
监听数据的代码:
db.collection("cities").where("createdDummyTime", ">", new Date().toISOString())
.onSnapshot((querySnapshot) => {
var cities = [];
querySnapshot.forEach((doc) => {
cities.push(doc.data().name);
});
console.log("Current cities in CA: ", cities.join(", "));
});
我什么也没收到,在我的测试中,也许我做错了
createdDummyTime
新数据