Page 1 of 1

How to count and return the total number of items in an array in database?

Posted: Tue Sep 08, 2015 12:28 pm
by Makoto

Hi, appery support team!

Is it possible to use $size (Array Aggregation Operator) in order to count and return the total number of items in an array in database? If not, is there any way to accomplish it?

I referenced to the following site.
https://docs.mongodb.org/master/refer...


How to count and return the total number of items in an array in database?

Posted: Tue Sep 08, 2015 8:36 pm
by Serhii Kulibaba

Hello Makoto,

Sure, it is possiple to use $size:
https://devcenter.appery.io/documenta...


How to count and return the total number of items in an array in database?

Posted: Tue Sep 08, 2015 11:18 pm
by Makoto

Hello Sergiy,

thank you very much for your help. But, I know $size makes it possible to retrieve elements in an array.

My question is how to use $size in order to “count and return the total number of items in an array in database”.

Thank you.


How to count and return the total number of items in an array in database?

Posted: Sat Sep 12, 2015 9:11 am
by Alena Prykhodko

Hello Makoto,

$size - standard MongoDB operator, it selects documents if the array field is a specified size.
Please find more here http://docs.mongodb.org/manual/refere...
To count total number of records you should you custom code.
This should be useful https://getsatisfaction.com/apperyio/...


How to count and return the total number of items in an array in database?

Posted: Mon Sep 14, 2015 1:08 pm
by Makoto

Hi Alena,

thank you for your reply. And, I could understand that it is not suitable to use $size operator for counting and returning the total number of items in an array in database when using Appery. I’ll try the method that you explained above. Thanks!