A newer version of this documentation is available.

View Latest

Import Filter

      +

      Introducing import filters and how to use them to speed-up the initial import process.

      Introduction

      The purpose of the import filter is to identify the subset of documents eligible to be replicated by Sync Gateway. This subset is based on application requirements, and is applied to all future mutations.

      Without a filter (the default), Sync Gateway imports all documents and so we recommend use of this import filter unless there is a compelling use-case against it.

      Function Provision

      Use the Database Configuration Admin Rest API endpoint /{db}/_config/import_filter 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

      Example 1. Using an Import Filter
      • API

      • Legacy

      //
      curl -X PUT "http://localhost:4985/froglist/_config/import_filter" \
      -H "accept: application/json" \
      -H "Content-Type: application/javascript" \
      -H "Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" \ (1)
      -d "\"function(doc) {\ if (doc.type != 'mobile') {\ return false\ }\ return true\}\\\""
      //
      1 You will need to provide authentication in the call; unless it is disabled (not recommended in production environment).
      //
      //  ... Preceding configuration data as required by the user ...
        {
        "databases": {
          "getting-started-db": {
            "bucket": "getting-started-bucket",
            "import_docs": true,
            "num_index_replicas": 0, (1)
            // ... other config as required
            "import_filter": `
            function(doc) { (2)
              if (doc.type != "mobile") {
                return false
              }
              return true
              }`,
            // ... other config as required
        }
        //  ... Further configuration data as required by the user ...
      
      //

      Configuration properties:

      1 The user’s username that you created on the Couchbase Server Admin Console.
      2 The user’s password that you created on the Couchbase Server Admin Console.
      3 The Sync with Couchbase Server feature allows Couchbase Server SDKs to also perform operations on this bucket.
      4 num_index_replicas is the number of index replicas stored in Couchbase Server, introduced with GSI/N1QL indexing — see Indexing. If you’re running a single Couchbase Server node for development purposes the num_index_replicas must be set to 0.
      5 Only import documents which have a type property equal to mobile.