Skip to content

Commit 17f26dc

Browse files
kennethdyerajhuh-mdbmdb-ashley
authored
DOCSP-31922 Filtered Sync Improvements (#154)
* DOCSP-31922 Regex and Exclude Filter Sync * Fixes build error * Removes fitler syntax from table * Adds filter syntax * Adds intro * Minor fix to trigger build * Adjusts intro text * Nests intro under versionchanged * Adjusts intro text * Adjusts intro text * Adjusts intro text * Adjusts intro text * Adjusts intro text * Expands Configure Filter step * Expands Use Filter step * Test alternate syntax highlighter * Fixes syntax highlighting options * Stubs Filter Regex * Stubs Filter Regex * Moves regex to new directory * Fixes build issue * Fixes build issue * Fixes build issue * Fixes build issue * Populates syntax documentation * Populates syntax documentation * Adds regex options * Adds regex options * Adds learn more link * Adds use case * Fixes build error * Fixes build error * Adds release notes * Fixes per Ali * Fixes per Ali Co-authored-by: Alison Huh <[email protected]> * Fixes per Ali * Fixes per Ali Co-authored-by: Alison Huh <[email protected]> * Fixes per Ali * Fixes per Ali * Fixes per Tim and Jessica * Fixes per Jessica * Fixes per Jessica * Fixes per Ashley Co-authored-by: Ashley Brown <[email protected]> --------- Co-authored-by: Alison Huh <[email protected]> Co-authored-by: Ashley Brown <[email protected]>
1 parent 028f1a7 commit 17f26dc

File tree

11 files changed

+298
-45
lines changed

11 files changed

+298
-45
lines changed

snooty.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ toc_landing_pages = ["/quickstart",
1919
"/using-mongosync",
2020
"/multiple-mongosyncs",
2121
"/release-notes/release-notes",
22-
"/faq"
22+
"/faq",
23+
"/reference/collection-level-filtering"
2324
]
2425

2526
[constants]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Starting in 1.6, the :ref:`c2c-api-start` API now supports the use of
3+
Regular Expressions to configure filters for the ``includeNamespaces``
4+
and ``excludeNamespaces`` parameters used in :ref:`c2c-filtered-sync`.
5+
6+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
If you configure a filter on a source cluster that has multiple
3+
databases, ``mongosync`` only syncs the databases specified in
4+
the filter definition. ``mongosync`` will not sync the other
5+
existing databases.
6+
7+
If you want to modify the filter to add a newly created database,
8+
you have to :ref:`restart the filtered sync <c2c-change-filter>`
9+
from the beginning.
10+
11+
For more details, see :ref:`c2c-filtered-sync`.
12+
13+
For current limitations, see :ref:`c2c-filtering-limitations`.
14+
File renamed without changes.

source/includes/api/requests/start-filtered.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ curl -X POST "http://localhost:27182/api/v1/start" --data '
22
{
33
"source": "cluster0",
44
"destination": "cluster1",
5-
"includeNamespaces" : [
5+
"includeNamespaces": [
66
{
7-
"database" : "sales",
8-
"collections": [ "EMEA", "APAC" ]
9-
},
10-
{
11-
"database" : "marketing"
7+
"database": "sales",
8+
"collectionRegex": {
9+
"pattern": "^accounts_.+$",
10+
"options": "i"
11+
}
12+
}, {
13+
"database": "marketing"
1214
}
1315
]
14-
} '
16+
} '

source/includes/example-filter-collection-with-renaming.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ databases.
1111
The ``includeNamespaces`` array in this example defines a filter on two
1212
of the databases:
1313

14-
.. code-block:: shell
14+
.. code-block:: json
1515
1616
{
1717
"source": "cluster0",
@@ -52,7 +52,7 @@ Renaming a Collection
5252

5353
You can rename any collection in the ``staff`` database.
5454

55-
.. code-block:: shell
55+
.. code-block:: javascript
5656
5757
// This code works
5858
use admin
@@ -62,7 +62,7 @@ You can only rename a collection within the ``students`` database if the
6262
new and old names are both in the filter. If either of the names is not
6363
in the filter, ``monogsync`` reports an error and exists.
6464

65-
.. code-block:: shell
65+
.. code-block:: javascript
6666
6767
// This code works
6868
use admin
@@ -71,7 +71,7 @@ in the filter, ``monogsync`` reports an error and exists.
7171
If a collection is specified in the filter, you can drop it, but you
7272
cannot rename it to remove it from the filter.
7373

74-
.. code-block:: shell
74+
.. code-block:: javascript
7575
:copyable: false
7676
7777
// This code produces an error and mongosync stops syncing
@@ -83,22 +83,22 @@ collections to add them to the filter:
8383

8484
- Source collection is specified in the filter
8585

86-
.. code-block:: shell
86+
.. code-block:: javascript
8787
8888
use admin
8989
db.runCommand( { renameCollection: "students.adjuncts", to: "staff.adjuncts" } )
9090
9191
- Source collection is not specified in the filter
9292

93-
.. code-block:: shell
93+
.. code-block:: javascript
9494
9595
use admin
9696
db.runCommand( { renameCollection: "prospects.current", to: "staff.newHires" } )
9797
9898
You can also rename collections in the source database when the whole
9999
target database is in the filter:
100100

101-
.. code-block:: shell
101+
.. code-block:: javascript
102102
103103
use admin
104104
db.runCommand( { renameCollection: "staff.employees", to: "staff.onPayroll" } )

source/includes/example-filter-collection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ of the databases, ``sales`` and ``marketing``.
1212
The ``sales`` database also filters on the ``EMEA`` and ``APAC``
1313
collections.
1414

15-
.. code-block:: javascript
15+
.. code-block:: json
1616
1717
"includeNamespaces" : [
1818
{

source/reference/api/start.txt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.. contents:: On this page
1111
:local:
1212
:backlinks: none
13-
:depth: 2
13+
:depth: 1
1414
:class: singlecol
1515

1616
Description
@@ -137,25 +137,20 @@ Request Body Parameters
137137
* - ``includeNamespaces``
138138
- array
139139
- Optional
140-
- Filters the databases or collections to sync. The filter syntax
141-
is:
140+
- Filters the databases or collections to include in sync.
142141

143-
.. include:: /includes/api/facts/includeNamespaces-syntax.rst
142+
.. include:: /includes/api/facts/namespace-explanation.rst
144143

145144
.. versionadded:: 1.1
146145

147-
If you configure a filter on a source cluster that has multiple
148-
databases, ``mongosync`` only syncs the databases specified in
149-
the filter definition. ``mongosync`` will not sync the other
150-
existing databases.
151-
152-
If you want to modify the filter to add a newly created database,
153-
you have to :ref:`restart the filtered sync <c2c-change-filter>`
154-
from the beginning.
146+
* - ``excludeNamespaces``
147+
- array
148+
- Optional
149+
- Filters the databases or collections to exclude from sync.
155150

156-
For more details, see: :ref:`c2c-filtered-sync`.
151+
.. include:: /includes/api/facts/namespace-explanation.rst
157152

158-
For current limitations, see: :ref:`c2c-filtering-limitations`.
153+
.. versionadded:: 1.6
159154

160155
* - ``reversible``
161156
- boolean

source/reference/collection-level-filtering.txt

Lines changed: 117 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2296
Configure 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

71168
For 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

Comments
 (0)