gpt4 book ai didi

firebase - Flutter Firestore-如何仅获取当前月份的数据?

转载 作者:行者123 更新时间:2023-12-03 03:35:03 29 4
gpt4 key购买 nike

大家。在下面的查询中,如何仅获取当月的数据?

我的Firestore数据库:

enter image description here

我的代码:

@override
Stream<List<TodoModel>> getTodos() {
return firestore.collection('todo')
.orderBy('myDate', descending: true)
.snapshots()
.map((query) {
return query.documents.map((doc) {
return TodoModel.fromDocument(doc);
}).toList();
});
}

知道我该怎么做吗?
谢谢

最佳答案

你可以试试这个吗

 Stream<List<TodoModel>> getTodos() {
var date = DateTime.now();
return Firestore.instance.collection('todo')
.where('myDate', isGreaterThanOrEqualTo: new DateTime(date.year, date.month, 1))
.orderBy('myDate', descending: true)
.snapshots()
.map((query) {
return query.documents.map((doc) {
return TodoModel.fromDocument(doc);
}).toList();
});
}

关于firebase - Flutter Firestore-如何仅获取当前月份的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61572581/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com