MongoDB 使用 C# 驱动程序是否有可用的文档验证器?
Is there Document Validator available for MongoDB using C# driver?
MongoDB documentation 讨论如何在插入或更新期间触发的集合上定义文档验证器。
例如,可以使用正则表达式验证包含电子邮件字段的集合,并且插入可能成功或失败,具体取决于集合在创建时的配置方式。
我还没有找到 MongoDB 的 C# 驱动程序的类似功能。
还不支持吗?
这艘船可能已经航行了,但如果其他人偶然发现了这个问题。这已经实现了。
主线 C# 驱动程序以及遗留 C# 驱动程序支持文档验证。正如您在 documentation, you set a validator when you create a collection (or by using collMod
to add a validator to an existing collection, but I won't discuss this further). The driver includes properties inside the CreateCollectionOptions
class for the Validator
document, the ValidationAction
, and ValidationLevel
. CreateCollectionOptions
is the second argument you pass to the CreateCollection
function. Here is the source code and a test that creates a collection with a simple validator and another 中看到的那样。
MongoDB documentation 讨论如何在插入或更新期间触发的集合上定义文档验证器。
例如,可以使用正则表达式验证包含电子邮件字段的集合,并且插入可能成功或失败,具体取决于集合在创建时的配置方式。
我还没有找到 MongoDB 的 C# 驱动程序的类似功能。
还不支持吗?
这艘船可能已经航行了,但如果其他人偶然发现了这个问题。这已经实现了。
主线 C# 驱动程序以及遗留 C# 驱动程序支持文档验证。正如您在 documentation, you set a validator when you create a collection (or by using collMod
to add a validator to an existing collection, but I won't discuss this further). The driver includes properties inside the CreateCollectionOptions
class for the Validator
document, the ValidationAction
, and ValidationLevel
. CreateCollectionOptions
is the second argument you pass to the CreateCollection
function. Here is the source code and a test that creates a collection with a simple validator and another 中看到的那样。