Regular Expressions in Filters
On this page
New in version 1.6.
Starting in 1.6, the start
API now supports the use of
Regular Expressions to configure filters for the includeNamespaces
and excludeNamespaces
parameters used in Filtered Sync.
Syntax
To match databases and collections for mongosync
to use Filtered Sync,
you can use regular expressions:
{ "databaseRegex": { "pattern": "<string>", "options": "<string>" }, "collectionsRegex": { "pattern": "<string>", "options": "<string>" } }
Regular expressions in filter documents use the following fields:
Option | Type | Description |
---|---|---|
| document | Specifies which collections you want the filter to match. |
| string | Regular expression options to use in the match. |
| string | Regular expression pattern to match. |
| document | Specifies which databases you want the filter to match. |
| string | Regular expression options to use in the match. |
| string | Regular expression pattern to match. |
These options are available to use with both the includeNamespaces
and excludeNamespaces
parameters.
Use Cases
Regular expressions allow you match multiple databases or collections with a single pattern. If you want to match multiple similarly named databases or collections, a regular expression may be easier to match than creating a series of filters for individual databases or groups of collections.
Details
Regular Expression Options
databaseRegex
and collectionsRegex
each supports an options
field,
which you can use to configure regular expression options.
Internally, mongosync
passes the filter and options to the
$regex
operator. Options available to that operator can be used
with Filtred Sync.
For example, this filter would match collections in the sales
database
that begin start with the accounts_
string:
"includeNamespaces": [ { "database": "sales", "collectionsRegex": { "pattern": "^accounts_.+?$", "options": "ms" } } ]