我成功地查询了时间戳早于当前日期的 Firestore 文档,如下所示:
import React from 'react'
import CircularProgress from '@material-ui/core/CircularProgress'
import { useSelector } from 'react-redux'
import { useFirestoreConnect } from 'react-redux-firebase'
import Grid from '@material-ui/core/Grid'
function MeetingHistory({ userId }) {
const todaysDate = new Date()
useFirestoreConnect([
{ collection: 'users',
doc: userId,
subcollections: [{ collection: 'scheduled',
where: [
['date', '<', todaysDate],
]
}],
storeAs: `${userId}-history-scheduled`
}
])
const pastMeetings = useSelector(state => state.firestore.ordered[`${userId}-history-scheduled`])
if (!pastMeetings) return (
<Grid container direction='row' alignItems='center' justify='center'>
<CircularProgress />
</Grid>
)
console.log('meetings', pastMeetings)
return (
<div>
<p>I am going to render past meeting data here</p>
</div>
)
}
export default MeetingHistory
但是,console.log('meetings', pastMeetings)
打印不断让我相信,由于当前日期随着时间的推移不断更新,我的数据库每秒都在被查询。看到 new Date() 不断变化是有道理的,但我不想要这种行为。我正在寻找一种方法来拍摄不会随时间变化的时间快照,并以此为基础进行查询。对此的任何解决方案将不胜感激。我的目标只是避免随着时间的推移经常查询。