Database Resync not processing all documents

Hello,
I am working on our sync function for our database.
However, I’m finding that it doesn’t process all of the documents.

For some simple testing, my sync function is simply:

function(doc) { channel(‘test’); }

If I run this query on the database
select count(*) as c from test where meta().id not like “_sync%”

I get the following result:

[
{
“c”: 318828
}
]

However, after I run a database resync, I get the following results when I ping the _resync endpoint:

{
“status”: “completed”,
“start_time”: “2026-03-17T21:20:02.123154357Z”,
“last_error”: “”,
“resync_id”: “1b72dd73-9d7c-45c5-aa94-69c359ac928e”,
“docs_changed”: 159510,
“docs_processed”: 159510,
“collections_processing”: {
“_default”: [
“_default”
]
}
}

This means that even though I have 318,828 documents in the database, only 159,510 were processed through the sync function. Why are nearly half of them getting skipped? It’s not like the channels weren’t updated, it’s that they weren’t even processed at all.

Here is one such document, when I call it from the _raw end point using the Sync Gateway:

{
“_id”: “00013be8-c790-48d3-b7d4-c7654665d8b5”,
“_rev”: “1-1ae3f19e282d776283d90c740ed8aa50”,
“organization”: “MyOrganization”,
“sourceInstance”: “00013be8-c790-48d3-b7d4-c7654665d8b5”,
“title”: {
“fieldType”: “text”,
“titleTextSize”: “large”,
“value”: “Title Here”,
“valueTextSize”: “large”
},
“type”: “_view”,
“_xattrs”: {
“_sync”: null,
“_globalSync”: null,
“_vv”: null,
“_mou”: null,
“$document”: {
“CAS”: “0x18892de139350000”,
“datatype”: [
“snappy”,
“json”
],
“deleted”: false,
“exptime”: 0,
“flags”: 0,
“last_modified”: “1767994774”,
“revid”: “1”,
“seqno”: “0x000000000000028a”,
“value_bytes”: 1189,
“value_crc32c”: “0x416c7080”,
“vbucket_uuid”: “0x000006ea65895c82”
}
}
}

There’s nothing I can see that’s particularly different about this document. But the _sync value is staying as null after the sync function is run. So, this document is completely skipped.

Is there a reason? What can I do to make the sync function resync all documents?

Thanks

I think this is a better question to determine the issue.

The particular database I’m working with is an XDCR from a previous database. And then a Sync Gateway was directed at it. (FWIW, this is Couchbase 8 / Sync Gateway 4).

Only half the documents are accessible through the Sync Gateway. But all of them are accessible with Sync Gateway’s _raw end point.

For example, this document:

{
“_id”: “abcd”,
“_rev”: “2-e992b9b16bd4dd1cc838180c8a8385ba”,
“columns”: [
{
“fieldType”: “text”,
“title”: “Name”,
“titleTextSize”: “large”,
“value”: “John Doe”,
“valueTextSize”: “large”
}
],
“filterValue”: null,
“id”: “abcd”,
“organization”: “MyOrg”
}

If I query it through

http://mysyncgateway:4985/database/_raw/abcd

I get:

{
“_id”: “abcd”,
“_rev”: “2-e992b9b16bd4dd1cc838180c8a8385ba”,
“columns”: [
{
“fieldType”: “text”,
“title”: “Name”,
“titleTextSize”: “large”,
“value”: “John Doe”,
“valueTextSize”: “large”
}
],
“filterValue”: null,
“id”: “abcd”,
“organization”: “MyOrg”,
“_xattrs”: {
“_vv”: null,
“_mou”: null,
“$document”: {
“CAS”: “0x187ffedc03000000”,
“datatype”: [
“snappy”,
“json”
],
“deleted”: false,
“exptime”: 0,
“flags”: 0,
“last_modified”: “1765409799”,
“revid”: “1”,
“seqno”: “0x000000000000075d”,
“value_bytes”: 2255,
“value_crc32c”: “0xc6cbd7c0”,
“vbucket_uuid”: “0x0000437e0ad3b096”
},
“_sync”: null,
“_globalSync”: null
}
}

But if I query it through:

http://mysyncgateway:4985/database/abcd

I get:

{
“error”:“not_found”,
“reason”:“Not found”
}

Why is this document not registered with the Sync Gateway?

Why are some accessible and some aren’t?

Thanks