I’ve developed a mobile app that replicates data from sync gateway to a local couchbase lite instance. We’ve been occasionally running into issues where it appears that not all documents have been replicated due to problems such as https://github.com/couchbase/couchbase-lite-ios/issues/2024 or simply missing documents due to issues in the upstream services that feed the documents into Couchbase, and I want to provide a tool to help verify the documents in cb lite match what is available in the cb cluster. I have a view on couchbase lite that can produce a count of documents by type. I’m thinking of providing a way to get the same information from sync gateway (filtered by the user’s channels) to compare the counts as a crude way to see if they match, and if not, which type(s) are mismatched. I’m also considering generating checksums to go a step further to validate the actual data. (Note: I know this would not likely be very useful in an environment where documents are frequently changing, but in my case they aren’t changing frequently, and when they do change it’s usually a bulk, off-hours thing.)
I have the same view in sync gateway, but apparently reduce doesn’t work there due to https://github.com/couchbase/sync_gateway/issues/857. I could run the view on sync gateway without reduce, get back all the results (possibly with multiple queries using limit and offset) and then reduce the results to counts myself, but it seems like a brute force, slow, costly approach. Does anyone have a better idea how to accomplish this goal? Would it be possible to query the server with N1QL to get these counts/checksums filtered by channel? Is there an entirely different approach that would work better?