Certain document won't sync through Sync Gateway

I’m running Couchbase server version 7.6.3 with Sync Gateway version 3.1. I have a stubborn document which won’t sync. There are many similar documents with the same channel which have no problem syncing. I’ve noticed that the xattr portion of the document metadata is an empty object, while the meta.flag value is 0. The other similar documents have a full xattr object and meta.flag equal to a non-0 value. I’d appreciate any ideas on why this one document isn’t syncing. Thanks in advance.

  1. Did you put a import_filter on specific documents in the SG config?
  2. Does your document have a field in the JSON of _id?

I don’t have an import_filter in my SG config, I do have import_docs set to true though. My document has the shape:

{
“displayName”: string,
“code”: number,
“name”: string,
“isTrapPest”: boolean,
“docType”: string,
“docState”: string,
“channelTypes”: string
}

As previously mentioned, I have other documents of this nature which don’t have an issue.

Is the document with no xattrs in the same collection with documents with xattrs?

Yes it is. I only have a single collection for all my documents.

What does your JS sync function look like.

function (doc, oldDoc, meta) {
  var source;
  if (doc._deleted || doc.docType === 'globalSettings') {
    channel('!');
    return;
  }

  if (doc.expiration !== undefined) {
    expiry(doc.expiration);
  }

  if (
    Array.isArray(doc.channelTypes) &&
    doc.channelTypes.length === 1
  ) {
    if(doc.channelTypes[0] === 'public') {
      channel('public');
      return;
    }
    if(doc.channelTypes[0] === 'recPublic') {
      channel('recPublic');
      return;
    }
  }
  if (doc.channelTypes === undefined || doc.channelTypes.length === 0) {
    if (
      doc.docType === 'scoutingTemplate' ||
      doc.docType === 'pest' ||
      doc.docType === 'lureType' ||
      doc.docType === 'mapNotePublic'
    ) {
      channel(doc.docType);
    } else {
      throw { forbidden: 'channelTypes needs to be present' };
    }
  } else {
    if (Array.isArray(doc.channelTypes)) {
      doc.channelTypes.forEach(function (chBy) {
        source = doc[chBy];
        if (source) {
          if (Array.isArray(source)) {
            channel(
              source.map(function (item) {
                return doc.docType + ':' + item.toString();
              })
            );
          } else {
            channel(doc.docType + ':' + source.toString());
          }
        }
      });
    } else {
      source = doc[doc.channelTypes];
      if (Array.isArray(source)) {
        channel(
          source.map(function (item) {
            return doc.docType + ':' + item.toString();
          })
        );
      } else {
        channel(doc.docType + ':' + source.toString());
      }
    }
  }
}

The channelTypes value of the document not syncing is ['public'], which is used by many other documents that are syncing successfully.

Try using my Sync Function Testing Tool to see if the Sync Function is doing what you want it to do.

"channelTypes": string

But you want an array/list.

if (
Array.isArray(doc.channelTypes) &&
doc.channelTypes.length === 1
) {
if(doc.channelTypes[0] === ‘public’) {
channel(‘public’);
return;
}

So shouldn’t "channelTypes":["public","abc","xyz"]

Use my Sync Function Testing Tool to see whats going on.