Docs Menu
Docs Home
/
MongoDB Cluster-to-Cluster Sync
/ /

Regular Expressions in Filters

On this page

  • Syntax
  • Use Cases
  • Details
  • Learn More

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.

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
collectionsRegex
document
Specifies which collections you want the filter to match.
collectionsRegex.options
string
Regular expression options to use in the match.
collectionsRegex.pattern
string
Regular expression pattern to match.
databaseRegex
document
Specifies which databases you want the filter to match.
databaseRegex.options
string
Regular expression options to use in the match.
databaseRegex.pattern
string
Regular expression pattern to match.

These options are available to use with both the includeNamespaces and excludeNamespaces parameters.

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.

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"
}
}
]
  • Filtered Sync

Back

Filtered Sync