Import Processing
Overview
The import process is a key part of mobile convergence. It’s the means by which Sync Gateway becomes aware of non-Sync Gateway data changes and obtains the mobile metadata it requires to replicate changes.
Operation
Any non-Sync Gateway change is eligible for import. For more information, refer to the Sync Function documentation.
The document is first run through the Sync Function to compute read security and routing, with the following differences:
-
The Sync Function processes the import using an admin user context, similar to how the Sync Gateway Admin API handles writes. This means the Sync Function treats
requireAccess,requireUser, andrequireRolecalls as no-ops. -
During import, the Sync Function executes with
oldDocset tonil.
When importing a deleted document:
-
Include the
docobject with the_deletedproperty set totrue. -
Do not include the
_idand_revfields in thedocobject. -
Include an explicit check for
doc._deletedin your import filter function to verify it handles deletions.
function(doc) {
// Always return true for deletions so they are not ignored during import
if (doc._deleted === true) {
return true;
}
// Only import mobile-type documents
if (doc.type != 'mobile') {
return false;
}
return true;
}
Check for the _deleted property to avoid skipping deletion events.
|
You can specify a filter function dynamically using /{keyspace}/_config/import_filter, or you can define one when you set up a database. Refer to the Import Filter Configuration documentation for more information.
Use the logging-console-log-keys in the Bootstrap Schema log key to troubleshoot import processing issues in the logs.
|
Function Provision
Use the Database Configuration Admin Rest API endpoint POST /{db}/_config to provision an import filter for a database using the application/javascript mime type.
If you are using legacy configuration then, you need to include it in your configuration file, see: import-filter.
Configuration
You need Couchbase Lite 3.1+ and Sync Gateway 3.1+ to use custom Scopes and Collections.If you’re using Capella App Services or Sync Gateway releases that are older than version 3.1, you won’t be able to access custom Scopes and Collections.
To use Couchbase Lite 3.1+ with these older versions, you can use the default Collection as a backup option.
|
The configuration settings described here are provisioned through the Database Configuration endpoints.
{
scopes: {
{scopename...}: {
collections: {
{collectionname...}: {
import_filter: "function(doc) { if (doc.type != 'mobile') { return false; } return true; }",
}
}
}
},
// other configuration
}
For more information, see Sync Gateway Configuration Schema.
| Property | Description |
|---|---|
scopename |
Represents the name of each scope |
collections |
Contains different collections within each scope |
collectionname |
Represents the name of each collection within a scope. |
import_filter |
Used to decide if a document should be imported. It checks the type property of the document. If it is not 'mobile', the function returns false, otherwise, it returns true. |