我想从昨天起获取所有文件。目前,在where
andisEqualTo
条件的帮助下,我设法获取了今天日期的所有数据。但是我无法从昨天的日期获得数据。
这是我的代码片段,可从中获取今日的文档。
谢谢您的帮助。
final uid = getCurrentUID();
final QuerySnapshot result = await FirebaseFirestore
.instance
.collection('School')
.doc(uid)
.collection('School_Data')
.where('Todays_Date', isEqualTo: todaysDate)
.get();
您可以像这样获得两个日期:
DateTime todaysDate = DateTime.now();
DateTime yesterdayDate = DateTime.utc(todaysDate.year, todaysDate.month, todaysDate.day -1);
如果只需要昨天的数据:
final QuerySnapshot result = await FirebaseFirestore
.instance
.collection('School')
.doc(uid)
.collection('School_Data')
.where('Todays_Date', isEqualTo: yesterdayDate)
.get();
如果您想从昨天开始获取数据,Firestore允许您在单个字段上执行范围(<,<=,>,> =)或不等于(!=)的比较:
final QuerySnapshot result = await FirebaseFirestore
.instance
.collection('School')
.doc(uid)
.collection('School_Data')
.where('Todays_Date', isGreaterThanOrEqualTo: yesterdayDate)
.where('Todays_Date', isLessThanOrEqualTo: todaysDate)
.get();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句