Hi everyone.
I am a beginner just getting started with Wix and learning Corvid Dev Tools. I have prepared a collection that looks like this:
I am now trying to make a script that does 3 things:
-
Get the total number of rows which I can then use as the total # of clients
-
identify how many unique countries are listed. So, here it should be India, America, Australia i.e., 3 in total
-
Sum up all work hours so here it should to 90
I have named this collection as “ClientCollection”. I would want to display these 3 results in a text box on my website. How would I go about doing this such that it is optimized for growing list i.e., as the list grows and if I parse it once per each of these results, this might slow down the website if the database is large. Look forward to suggestions and support.
#database #corvid wix #statistics #analytics
Hello Kshitij TIWARI,
- To get the total number you will need something like this…
first you make a query… a query of your collection…
import wixData from 'wix-data';
// ...
wixData.query("myCollection")
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0]; //see item below
} else {
// handle case where no matching items found
}
} )
- Then you can figure out the length of the query…
let lengthOfData = results.length
- So if you expand your CODE, it will look like this…
wixData.query("myCollection <---- change this here --->")
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0]; //see item below
let lengthOfData = results.length
console.log(firstItem)
console.log(lengthOfData)
for (var i = 0; i < lengthOfData; i++) {
let selectedItem = results.items[i].country
console.log(selectedItem)
//Press F12 and look at ---> CONSOLE (in Google-Browser)
}
}
else {
// handle case where no matching items found
}
})
Of course this code-snipet is not complete.
So its now on you to complete the rest.
The “Corvid-API-Reference” will help you to solve your problems with coding…
https://www.wix.com/corvid/reference/