Flutter查询集合的字段

时间:2018-10-15 12:04:56

标签: firebase dart flutter google-cloud-firestore

我使用以下代码创建了一个messages集合;

var documentReference = Firestore.instance
          .collection('messages')
          .document(groupChatId)
          .collection(groupChatId)
          .document(DateTime.now().millisecondsSinceEpoch.toString());

      Firestore.instance.runTransaction((transaction) async {
        await transaction.set(
          documentReference,
          {
            'idFrom': _cuserID,
            'idTo': chatWith,
            'timestamp': DateTime.now().millisecondsSinceEpoch.toString(),
            'content': content,
            'type': type,
            'hasRead': false
          },
        );
      });

我想查询上面的集合,选择与where查询匹配的文档。 下面是到目前为止的代码,请帮忙;

QuerySnapshot myChats =
        await Firestore.instance.collection('messages').where('idTo', isEqualTo: currentUser.uid).getDocuments();

我会输入在创建期间使用的文档值groupChatId和集合值groupChatId,但是由于它们不是唯一的,因此无法检索它们。

0 个答案:

没有答案