Replication depth

I have noticed that my client devices are replicating a huge number of records on initial login. I would like a proposal on how I can configure the replication depth to only replicate necessary records. The docs don’t mention the best practice or ideal setup.

I don’t believe there is a best practice or ideal setup, it all depends on your config and what data is required to reach your users’ devices. In the end, it will be your choice entirely.

Maybe if you share your setup and what reports / contacts you get on various levels, we might guide you a bit.

 "replication_depth": [
      "role": "chw",
      "depth": 0
      "role": "chw_logout",
      "depth": 1
      "role": "chw_supervisor",
      "depth": 2

My current setup

Which of these user roles are getting too many docs?

Both chw and chw_supervisor

A replication depth of 0 means that the user can only see reports and contacts from their own level. Depending on the hierarchy, this might not be correct for your CHW. A replication depth of 2 might be too much for your supervisor, you might want to reduce that to a 1.
Again, this depends on your config.

Have you tried looking at purging to filter out docs that are not required on devices?

Thanks for the recommendation. I have adjusted accordingly.
In regards to purging, here’s my script:

module.exports = {
    cron: '15 * ? * *',
    fn: (userCtx, contact, reports, messages) => {
      const NOW =;
      const monthsAgo = months => NOW - 1000 * 60 * 60 * 24 * 30 * months;
      const SCHW_WORKFLOWS = [
      const reportsToPurge = reports.filter(r => {
        if (userCtx.roles.includes('chw') && !SCHW_WORKFLOWS.includes(r.form)){
          return true;
        const purgeThreshold = ['pregnancy', 'pregnancy_follow_up'].includes(r.form) ? 12 : 6;
        return r.reported_date <= monthsAgo(purgeThreshold);
      }).map(r => r._id);
      const messagesToPurge = messages.filter(
        m => m.reported_date <= monthsAgo(6)
      ).map(m => m._id);
      return [...reportsToPurge, ...messagesToPurge];

I can’t be sure how impactful your purging script is, it depends on the number of reports of each type that you have. I suggest you review it, if it proves insufficient.
Typically, CHWs should not have replication depth.

Thanks, let me adjust my replication depths