Firestore - how to get the total number of records in a collection like we are doing in sql [duplicate]

…衆ロ難τιáo~ 提交于 2021-02-11 13:28:47

问题


db.collection("cities").get().then(function(querySnapshot) { 
console.log(querySnapshot.size); }); 

but the problem is I am using pagination and load 30 records for each call. so I am unable to get the total numbers of records. Is there any way to get it ? like, we are doing in sql.


回答1:


How to get the total number of records in a collection with Firebase ?

The method numChildren() do that. You can find more information about it here

Here is an example to use it:

db.collection("cities").get().then(function(querySnapshot) { 
    console.log(querySnapshot.numChildren());
});

I hope my answer help you 😊



来源:https://stackoverflow.com/questions/53532615/firestore-how-to-get-the-total-number-of-records-in-a-collection-like-we-are-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!