mongodb Regex过滤字符串数组项目
这是文档结构
{
"_id" : ObjectId("6284f3eceae4fd4c3cfebb39"),
"Codes" : [
"Code 1",
"Code 2",
"Code 3"
]
}
,我也有Mongo查询,它可以按预期工作
{ "Codes" : { "$elemMatch" : { "$regex" : /code/, $options: 'si' } } }
,但是当我尝试使用MongoDB驱动程序编写C#代码
var filter = Builders<MyClass>.Filter
.ElemMatch(x => x.Codes,
Builders<string>.Filter.Regex(c => c, new BsonRegularExpression($"/^{codeFilter}/is")));
并执行此过滤器定义时,我有异常
system.invalidoperationException:'无法确定 C =&GT的序列化信息; c。'
我的错误在哪里?如何创建过滤定义以使用$ REGEX
运算符检查字符串数组项目?
Here is document structure
{
"_id" : ObjectId("6284f3eceae4fd4c3cfebb39"),
"Codes" : [
"Code 1",
"Code 2",
"Code 3"
]
}
Also i have mongo query which works as expected
{ "Codes" : { "$elemMatch" : { "$regex" : /code/, $options: 'si' } } }
But when i tried to write C# code with mongodb driver
var filter = Builders<MyClass>.Filter
.ElemMatch(x => x.Codes,
Builders<string>.Filter.Regex(c => c, new BsonRegularExpression(quot;/^{codeFilter}/is")));
and execute this filter definition i've got an exception
System.InvalidOperationException: 'Unable to determine the
serialization information for c => c.'
Where is my mistake? How can i create filter definition to check string array items with $regex
operator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您为正则构建器创建了错误的通用类型:
实体结构在哪里:
You created wrong generic type for regex builder:
where the entities structure are: