简体   繁体   中英

Flutter Firestore - how to get the current month's data only?

everyone. In the query below how can I get only the data for the current month?

my firestore DB:

在此处输入图像描述

my code:

@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();
 });
}

Any idea how I can do that? Thanks

Can you try this

 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();
    });
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM