【发布时间】:2021-03-03 15:54:55
【问题描述】:
假设我们有一个不断增长的餐厅数据库,用户可以喜欢它们。我想显示本月最受欢迎的 10 家餐厅。
我们确实需要一种降级的餐厅,并且我们需要定义一个范围。现在,当我偶然发现 firebase 文档时,我们在这里达到了极限。你将如何实现它?
QuerySnapshot snapshot =
await FirebaseFirestore.instance
.collection('restaurants')
.orderBy('likes', descending: true)
.limit(10)
.get()
.catchError((error) => print("---- $error"));
在我的代码示例中,我们可以完成以下操作:
[x] get all restaurants ordered by likes descending
[x] limit them to the top 10
[ ] only pick restaurants of the last 30 days
假设每家餐厅都有一个uploadDate 值,即Timestamp。如何将我们的结果附上过去 30 天的uploadDate?
【问题讨论】:
标签: firebase flutter google-cloud-firestore