localbase icon indicating copy to clipboard operation
localbase copied to clipboard

how do I get collection length?

Open sarwarcse opened this issue 3 years ago • 3 comments

if there is a table named customer. then how can I get the counter of total customers.

Another scenario is : if I have multiple status of customer, where active customer is more then 100. I want to show the counter of total active customer but I will get 10 rows of 100; I want to make a response like this :

 let response ={
      total_rows:100, 
      row_limit:10,
      total_page:10,
      current_page:1, // it means 0 to 10 positions data
      rows:[{1},{},....{10}]
  };
//db.collection('customers').doc({status:"active"});

sarwarcse avatar Aug 10 '21 07:08 sarwarcse

For the counter I just grab the collection and assign it to a variable. Using variablename.length you get how many objects (in this case customers) there are.

Localbase is similar to Firebase but I haven't seen in the docs anything about how to handle limiting docs into groups. You can limit to 50 but it only returns the first 50. I can't help you with fetching 50+ and limiting from there but because it is local you could use vuex or even just a function to return what you need.

teamsuperpanda avatar Sep 12 '21 11:09 teamsuperpanda

I also would like to be able to get count or length much like in SQL. I don't know if it's the same here but I'm SQL is faster to call count than to get all the records and get the length of the result.

Jargonius avatar Apr 15 '22 22:04 Jargonius