gpt4 book ai didi

mongodb - MongoDb 中子文档字段的 $match 运算符

转载 作者:可可西里 更新时间:2023-11-01 09:20:32 26 4
gpt4 key购买 nike

我正在尝试 MongoDB 的新管道查询,所以我尝试执行以下查询。

{
aggregate: 'Posts',
pipeline: [
{ $unwind: '$Comments'},
{ $match: {'$Comments.Owner': 'Harry' }},
{$group: {
'_id': '$Comments._id'
}
}
]
}

没有匹配查询所以返回空结果。我想问题可能出在 $match 命令上。我正在使用点分符号匹配评论所有者,但不确定它是否完全正确。为什么这个查询不返回 Ownders who is 'Harry' 。我确定它存在于数据库中。

最佳答案

您不要为 $match 字段名称使用 $ 前缀。

试试这个:

{
aggregate: 'Posts',
pipeline: [
{ $unwind: '$Comments'},
{ $match: {'Comments.Owner': 'Harry' }},
{ $group: {
'_id': '$Comments._id'
}}
]
}

关于mongodb - MongoDb 中子文档字段的 $match 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8662138/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com