arrays - Mongo 错误 - 无法规范化查询:BadValue 不支持的投影选项
问题描述
我是 MongoDB 新手,正在尝试执行查询。我有一个公司集合和公司 ID 数组。我想得到attributes.0.ccode
存在attributes.0.ccode
且不为空的结果,并将在 array( cdata
)中提供的 id 中进行检查
var query = Company.find({ _id: { $in: cdata } },{ "attributes.0.ccode": { $exists: true }, $and: [ { "attributes.0.ccode": { $ne: "" } } ] }).select({"attributes": 1}).sort({});
我得到的错误是
"$err": "Can't canonicalize query: BadValue Unsupported projection option: attributes.0.ccode: { $exists: true }",
"code": 17287
我认为这是一个括号问题,但无法弄清楚在哪里。
非常感谢任何帮助。
解决方案
在您的代码{ _id: { $in: cdata } }
中被解释为查询,以及其他所有内容,从,{ "attributes.0.ccode": { $e..
Projection(要显示的字段)开始。尝试重构您的代码,以便_id: {$in ...}
查询的其余部分属于同一个更高级别的对象。像这样的东西:
var query = Company.find({
_id: {
$in: cdata
},
"attributes.0.ccode": {
$exists: true
},
$and: [
{
"attributes.0.ccode": {
$ne: ""
}
}
]
}).select({"attributes": 1}).sort({});
推荐阅读
- r - 如何关闭 Rstudio 中的火花连接?
- postgresql - 错误:Compose 文件“.\docker-compose.yml”无效,因为:services.drupal 的配置选项不受支持:“postgres”
- azure - 在 Azure Pipelines 中使用 Web 应用管理任务时收到“由于权限不足而无法读取配置文件”
- reactjs - 卡片不在纸上居中 - Material-ui React App
- python - 如果数据集缺少值,如何在python中将名义数据转换为数字?
- java - 如何访问序列化对象以从另一种方法更新其数据?
- python - pyautogui 在照片中多次搜索照片
- python - 导入本地模块的最佳方式是什么?
- postgresql - 在只读副本上运行真空分析是否安全?
- flutter - Flutter FCM:Ios发送数据有效载荷