Firestore 查询 orderBy 不起作用? [英] Firestore query orderBy not working?

查看:32
本文介绍了Firestore 查询 orderBy 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FutureBuilder 在类型时间戳字段上执行 Firestore 查询返回快照中没有数据.但是,没有 orderBy 的相同查询也可以正常工作.
我错过了什么?感谢您的帮助.

FutureBuilder with a Firestore query on a field of Type timestamp comes back with no data in snapshot. However, the same query without the orderBy works just fine.
What am I missing ? Thanks for the help.

// Working code
future: Firestore.instance.collection('messages').where('toid',isEqualTo: _emailID).getDocuments(),
builder: (context, snapshot) ...

// Not Working - returns to if(!snapshot.hasData)
future: Firestore.instance.collection('messages').where('toid',isEqualTo: _emailID).orderBy('_timeStampUTC', descending: true).getDocuments(),
builder: (context, snapshot) ...

推荐答案

我认为你在这里缺少一个 ' '_timeStampUTC,所以它应该是:

I think you are missing a ' here '_timeStampUTC, so it should be:

 orderBy('_timeStampUTC', descending: true)

此外,您需要确保为 toid 和其他_timeStampUTC 创建索引,当您尝试按不在您是查询的位置.

Also, you need to be sure to create an index for toid and other for _timeStampUTC, this is done when you try to order by a property that is not in you the where of the query.

这篇关于Firestore 查询 orderBy 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆