对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

过滤器中的正则表达式

1.6版本新增。

从 1.6 开始, start API 现在支持使用正则表达式为筛选同步中使用的includeNamespacesexcludeNamespaces参数配置筛选器。

要匹配数据库和collection,以便mongosync使用Filtered Sync ,可以使用正则表达式:

{
"databaseRegex": {
"pattern": "<string>",
"options": "<string>"
},
"collectionsRegex": {
"pattern": "<string>",
"options": "<string>"
}
}

The regular expression pattern you pass into a filter must follow the regex syntax supported by the MongoDB server.

Regular expressions in filter documents use options listed in the regex guide. options is a string of concatenated options. For example, to specify the i and s options, pass in "si" to options. The order of concatenated options does not matter.

筛选器文档中的正则表达式使用以下字段:

选项
类型
说明

collectionsRegex

文档

指定您希望筛选器匹配哪些集合。

collectionsRegex.options

字符串

匹配中使用的正则表达式选项。

collectionsRegex.pattern

字符串

要匹配的正则表达式模式。

databaseRegex

文档

指定您希望筛选器匹配哪些数据库。

databaseRegex.options

字符串

匹配中使用的正则表达式选项。

databaseRegex.pattern

字符串

要匹配的正则表达式模式。

这些选项可与includeNamespacesexcludeNamespaces参数一起使用。

正则表达式允许您将多个数据库或collection与单个模式进行匹配。如果要匹配多个名称相似的数据库或collection,与为单个数据库或collection群组创建一系列筛选器相比,正则表达式可能更容易匹配。

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.

示例,此过滤将匹配 sales数据库中以 accounts_ 字符串开头的集合。 过滤还指定选项 m,以匹配具有多行值的字符串每行开头或结尾的字符,并指定选项 s,以允许点字符匹配包括换行符在内的所有字符。

"includeNamespaces": [
{
"database": "sales",
"collectionsRegex": {
"pattern": "^accounts_.+?$",
"options": "ms"
}
}
]
给本页内容打分