mongodb:匹配数组字段中没有子字符串的文档
我正在尝试在聚合管道中匹配数组字段中没有子字符串的文档。
我相信我需要添加一个字段,然后在 -1
上执行 $match
,但我坚持在 $indexOfBytes
上查找子字符串在数组字段中。
db.collectionName.aggregate([{$addFields:{indexOfA:{$indexOfBytes:['$arrayName.fieldName1.fieldName2','A']}}}])
我收到错误:
MongoServerError: PlanExecutor error during aggregation :: caused by :: $indexOfBytes requires a string as the first argument, found: array
集合示例:
[
{ arrayName: [ fieldName1: { fieldName2: 'A' } ] },
{ arrayName: [ fieldName1: { fieldName2: 'B' } ] },
{ arrayName: [ fieldName1: { fieldName2: 'C' } ] },
{ arrayName: [ ] }
]
所需结果(:
[
{ arrayName: [ fieldName1: { fieldName2: 'B' } ] },
{ arrayName: [ fieldName1: { fieldName2: 'C' } ] },
{ arrayName: [ ] }
]
I'm trying to match documents without a substring in an array field, in an aggregation pipeline.
I believe I need to add a field and then do a $match
on -1
, but I'm stuck on $indexOfBytes
to find substrings in an array field.
db.collectionName.aggregate([{$addFields:{indexOfA:{$indexOfBytes:['$arrayName.fieldName1.fieldName2','A']}}}])
I get the error:
MongoServerError: PlanExecutor error during aggregation :: caused by :: $indexOfBytes requires a string as the first argument, found: array
collection example:
[
{ arrayName: [ fieldName1: { fieldName2: 'A' } ] },
{ arrayName: [ fieldName1: { fieldName2: 'B' } ] },
{ arrayName: [ fieldName1: { fieldName2: 'C' } ] },
{ arrayName: [ ] }
]
desired result (:
[
{ arrayName: [ fieldName1: { fieldName2: 'B' } ] },
{ arrayName: [ fieldName1: { fieldName2: 'C' } ] },
{ arrayName: [ ] }
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许是这样的东西:
解释:
游乐场
Maybe something like this:
Explained:
playground