本文介绍了我可以按Firebase Firestore中对象的长度排序结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Firestore文档中有一个投票"字段,其中存储了对该文档进行投票的人员的uid.

I have a votes field in my firestore documents, in which I store the uids of the people that have voted on that document.

我想调用所有文档,并按投票对象中的投票数对其进行排序.

I would like to call all the documents and order them by the number of votes in the votes object.

我尝试了db.collection('myCollection').orderBy(Object.keys('votes').length)...,但是作为orderBy参数无效.

I tried db.collection('myCollection').orderBy(Object.keys('votes').length)... but that is not valid as an orderBy parameter.

我也尝试过'votes.size',但是没有运气.

I also tried 'votes.size' but no luck.

有什么方法可以按照Firebase Firestore中对象的长度来排序查询结果?

Is there any way to order results of a query by the length of an object in the firebase firestore?

推荐答案

在文档中添加votesCount键,并使用firebase函数在每次投票时重新计算计数.然后订购.

Add a votesCount key to the documents and a firebase function that recalculates the count every time there is a vote. Then order on that.

这篇关于我可以按Firebase Firestore中对象的长度排序结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:33