@@ -18,20 +18,34 @@ Filtered Sync
1818.. include:: /includes/api/facts/filtering-intro.rst
1919
2020Starting in 1.1, ``mongosync`` supports inclusion filters to specify which
21- databases and collections to include in sync.
21+ databases and collections to include in sync. Starting in 1.6, ``mongosync``
22+ also supports exclusion filters and regular expressions.
2223
2324- With inclusion filters, ``mongosync`` syncs matching
2425 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.
2531- With no filters, ``mongosync`` syncs all databases and collections.
2632
2733.. _c2c-filter-syntax:
2834
2935Filter Syntax
3036-------------
3137
32- The :ref:`c2c-api-start` API endpoint accepts one field to configure filtered
33- sync: ``includeNamespaces``. This field takes an array of filters to specify
34- the databases and collections to include in the sync.
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.
3549
3650Filters have the following syntax:
3751
@@ -44,10 +58,38 @@ Filters have the following syntax:
4458 "collections": [
4559 "<collection-name>"
4660 ]
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+ }
4785 }
4886 ]
4987
50- Filters must include the ``database`` field.
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.
5193
5294.. _c2c-configure-filter:
5395
@@ -66,41 +108,53 @@ Configure a Filter
66108 .. step:: Identify Databases and Collections.
67109
68110 Identify the databases and collections that you want to sync to
69- the destination cluster. When you add a set of databases to the
70- filter, you also exclude any other databases in the cluster.
111+ the destination cluster.
112+
113+ - When you add a set of databases to the filter, you also exclude any
114+ other databases in the cluster.
71115
72- When you specify a collection in your filter, you also exclude any
73- other collections that are in the same database.
116+ - When you specify a collection in your filter, you also exclude any
117+ other collections that are in the same database.
74118
75119 .. step:: Create a Filter.
76120
77- The :ref:`c2c-api-start` API accepts a parameter to configure a series of
121+ The :ref:`c2c-api-start` API accepts two parameters that configure
78122 optional filters:
79123
80124 - The ``includeNamespaces`` parameter takes an array of filters, which
81125 are used to determines which databases and collections ``mongosync``
82126 should include in the sync.
127+ - The ``excludeNamespaces`` parameter takes an array of filters, which
128+ are used to determine which databases and collections ``mongosync``
129+ should exclude from the sync.
83130
84131 If you don't specify a filter, ``mongosync`` performs a full cluster
85132 sync.
86133
87- Create inclusion filters to identify the databases and
134+ Create inclusion and/or exclusion filters to identify the databases and
88135 collections you want to sync.
89136
90137 For example, this inclusion filter would configure ``mongosync`` to only
91- sync ``accounts_us`` and ``accounts_eu `` collections in the ``sales``
92- database.
138+ sync collections whose names begin with ``accounts_ `` from the ``sales``
139+ database, except for the ``accounts_old`` collection:
93140
94141 .. code-block:: json
95142
96143 "includeNamespaces": [
97144 {
98145 "database": "sales",
99- "collections": [
100- "accounts_us",
101- "accounts_eu",
102- ]
103- }
146+ "collectionRegex": {
147+ "pattern": "^accounts_.+?$",
148+ "options": "ms"
149+ }
150+ ],
151+ "excludeNamespaces": [
152+ {
153+ "database": "sales",
154+ "collections": [
155+ "accounts_old"
156+ ]
157+ }
104158 ]
105159
106160 For more information on filters, see :ref:`c2c-filter-syntax`.
@@ -298,3 +352,8 @@ Adding and Renaming Collections While Syncing
298352
299353.. include:: /includes/example-filter-collection-with-renaming.rst
300354
355+ .. toctree::
356+ :hidden:
357+
358+ /reference/collection-level-filtering/filter-regex
359+
0 commit comments