count can be used on a collection to count all Documents matching the provided requirements. If no requirements are provided, all documents will be counted.

count will return the amount of matches.

try collection.count() // returns 5

Count also accepts the parameter matching which requires a Query to be provided.

try collection.count(matching: "first_name" == "Joannis") // returns 1 if only one user is named Joannis

For more information about counting documents, click here

On this page