Total number of documents can be counted in sync function or server side?

I use sync_gateway in my socail app to sync Identity documents and InfoCard documents between apps and server.
There are several socail actions to the InfoCard, such as like action, comment action and save action,
be stored in a seperate type document.

Is there any method I can use in the sync function to count the total number of each social action type to some InfoCard?

Or on the Couchbase Server side, is there any method I can user to trace the social action Create or Update event,
and use the RxJava and reactive programming to count the total number of each social action type on some InfoCard?

There’s nothing in the Sync Function for this functionality - this sounds like an operation that would typically be performed by a view or N1QL query.

Thanks a lot for the reply.

If using view or N1QL query, it should be executed by interval.
But I want to update the count number reactively when social action is stored into the Couchbase Server by Sync_gateway.
Is there any api can be executed when any document be created on Server side?