@@ -17,6 +17,80 @@ Filtered Sync
1717
1818.. include:: /includes/api/facts/filtering-intro.rst
1919
20+ Starting in 1.1, ``mongosync`` supports inclusion filters to specify which
21+ databases and collections to include in sync. Starting in 1.6, ``mongosync``
22+ also supports exclusion filters and regular expressions.
23+
24+ - With inclusion filters, ``mongosync`` syncs matching
25+ databases and collections.
26+ - With exclusion filters, ``mongosync`` syncs all databases
27+ and collections, except for those that match the filters.
28+ - With both inclusion and exclusion filters, ``mongosync`` only syncs
29+ databases and collections that match the inclusion filters then excludes
30+ any that also match the exclusion filters.
31+ - With no filters, ``mongosync`` syncs all databases and collections.
32+
33+ .. _c2c-filter-syntax:
34+
35+ Filter Syntax
36+ -------------
37+
38+ The :ref:`c2c-api-start` API endpoint accepts two fields that configure
39+ filtered sync: ``includeNamespaces`` and ``excludeNamespaces``.
40+ Each field takes an array of filters that specify the databases and collections
41+ to include or exclude from sync.
42+
43+ .. note::
44+
45+ If the :ref:`c2c-api-start` call uses both ``includeNamespaces`` and
46+ ``excludeNamespaces`` parameters, ``mongosync`` first matches databases
47+ and collections from the inclusion filters, then excludes those that
48+ also match an exclusion filter.
49+
50+ Filters have the following syntax:
51+
52+ .. code-block:: json
53+ :copyable: false
54+
55+ "includeNamespaces": [
56+ {
57+ "database": "<database-name>",
58+ "collections": [
59+ "<collection-name>"
60+ ]
61+ "databaseRegex": {
62+ "pattern": "<regex-pattern>",
63+ "options": "<options>"
64+ },
65+ "collectionRegex": {
66+ "pattern": "<regex-pattern>",
67+ "options": "<options>"
68+ }
69+ }
70+ ],
71+ "excludeNamespaces": [
72+ {
73+ "database": "<database-name>",
74+ "collections": [
75+ "<collection-name>"
76+ ]
77+ "databaseRegex": {
78+ "pattern": "<regex-pattern>",
79+ "options": "<options>"
80+ },
81+ "collectionRegex": {
82+ "pattern": "<regex-pattern>",
83+ "options": "<options>"
84+ }
85+ }
86+ ]
87+
88+ Filters must include either the ``database`` field or the ``databaseRegex`` field.
89+
90+ If you need the filter to match specific collections, you can use either
91+ the ``collections`` array to specify collections individually or define
92+ a regular expression using the ``collectionRegex`` field.
93+
2094.. _c2c-configure-filter:
2195
2296Configure a Filter
@@ -42,31 +116,54 @@ Configure a Filter
42116
43117 .. step:: Create a Filter.
44118
45- The ``includeNamespaces`` parameter specifies an optional filter
46- that you can pass to the :ref:`/start <c2c-api-start>` API.
119+ The :ref:`c2c-api-start` API accepts two parameters that configure
120+ optional filters:
47121
48- If you don't specify a filter, ``mongosync`` does a full cluster
122+ - The ``includeNamespaces`` parameter takes an array of filters, which
123+ are used to determines which databases and collections ``mongosync``
124+ should include in the sync.
125+ - The ``excludeNamespaces`` parameter takes an array of filters, which
126+ are used to determine which databases and collections ``mongosync``
127+ should exclude from the sync.
128+
129+ If you don't specify a filter, ``mongosync`` performs a full cluster
49130 sync.
50131
51- The filter syntax is:
52-
53- .. include:: /includes/api/facts/includeNamespaces-syntax.rst
54-
55- Create an entry in the ``includeNamespaces`` array for each
56- database that you identified in step 1. Use the ``"database"``
57- field to specify the database name.
58-
59- If you want to filter on collections within a database, add those
60- collections to the list in the ``"collections"`` field for that
61- database entry.
132+ Create inclusion and/or exclusion filters to identify the databases and
133+ collections you want to sync.
134+
135+ For example, this inclusion filter would configure ``mongosync`` to only
136+ sync collections whose names begin with ``accounts_`` from the ``sales``
137+ database, except for the ``accounts_old`` collection:
138+
139+ .. code-block:: json
140+
141+ "includeNamespaces": [
142+ {
143+ "database": "sales",
144+ "collectionRegex": {
145+ "pattern": "^accounts_.+$",
146+ "options": "ms"
147+ }
148+ ],
149+ "excludeNamespaces": [
150+ {
151+ "database": "sales",
152+ "collections": [
153+ "accounts_old"
154+ ]
155+ }
156+ ]
157+
158+ For more information on filters, see :ref:`c2c-filter-syntax`.
62159
63160 .. step:: Use the Filter.
64161
65162 To use the filter, attach the filter json when you make the
66163 :ref:`/start <c2c-api-start>` API call to begin syncing.
67164
68165 .. literalinclude:: /includes/api/requests/start-filtered.sh
69- :language: shell
166+ :language: bash
70167
71168For an example configuration, see: :ref:`c2c-example-start-with-filter`.
72169
@@ -253,3 +350,8 @@ Adding and Renaming Collections While Syncing
253350
254351.. include:: /includes/example-filter-collection-with-renaming.rst
255352
353+ .. toctree::
354+ :hidden:
355+
356+ /reference/collection-level-filtering/filter-regex
357+
0 commit comments