Node.js 如何在Firestore中正确执行按日期查询?
我试图创建一个cronjob来删除使用http触发器传递的事件。今天是9月7日,因此9月5日的事件(Node.js 如何在Firestore中正确执行按日期查询?,node.js,firebase,google-cloud-firestore,google-cloud-functions,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,我试图创建一个cronjob来删除使用http触发器传递的事件。今天是9月7日,因此9月5日的事件(6fqmROcWD7K1pTFtXmJJ)将在查询快照中捕获,如下图所示。但文档长度为零 以下是我使用的代码: export const cronJobDeletingPastEvents = functions.https.onRequest(async (request,response) => { const dateNow = Date.now()
6fqmROcWD7K1pTFtXmJJ
)将在查询快照中捕获,如下图所示。但文档长度为零
以下是我使用的代码:
export const cronJobDeletingPastEvents = functions.https.onRequest(async (request,response) => {
const dateNow = Date.now()
const pastEventsSnapshot = await admin.firestore().collection("events").where('dateTimeFinish', '<', dateNow).get()
console.log(pastEventsSnapshot.docs.length) // <---- the result is zero
// perform some actions ....
}
export const cronJobDeletingPastEvents=functions.https.onRequest(异步(请求,响应)=>{
const dateNow=Date.now()
const pastEventsSnapshot=await admin.firestore().collection(“事件”)。其中('dateTimeFinish','以下选项将起作用:
const dateNow = new Date()
const pastEventsSnapshot = await admin.firestore().collection("events").where('dateTimeFinish', '<', dateNow).get()
...
以下工作将起作用:
const dateNow = new Date()
const pastEventsSnapshot = await admin.firestore().collection("events").where('dateTimeFinish', '<', dateNow).get()
...