database - 如何解决 MongoDB 查询括号错误?
问题描述
db.restaurants.find({ $or: [ { $and: [ {cuisine: {$ne: 'American'}}, {cuisine: {$ne: 'Chinese'}} ] }]}, {name: "/^Wil/"} ] }, {name: 1, cuisine:1})
错误:
uncaught exception: SyntaxError: missing ) after argument list :
这些长查询有很多括号,我无法正确匹配它们。是否有我们应该用于编写这些查询的特定工具/IDE?
解决方案
试试这个:
db.restaurants.find({
$or: [
{
$and: [
{
cuisine: {
$ne: "American"
}
},
{
cuisine: {
$ne: "Chinese"
}
}
]
},
{
name: /^Wil/
}
]
},
{
name: 1,
cuisine: 1
})
对于非常简单的查询,请使用MongoPlayground。
对于更复杂的查询,我通常使用Robo3t / Studio3t
.
推荐阅读
- c - 带符号整数的位移位重置太多
- angular - 是否可以通过 HttpInterceptors 添加 'observe': 'response' httpOption?
- javascript - 刷新后反应数据表不重新填充
- flutter - 我的浮动操作按钮没有从一个屏幕更改到另一个屏幕
- graphql - 放大/反应 AppSync graphql 订阅 @auth 错误
- android - Koin DI 清除依赖
- r - R中我的班级名称中的大写字母问题
- python - 如何根据 Git 子模块的需要对父存储库进行版本控制?
- powershell - 在 Powershell 中识别外部和内部硬盘驱动器
- excel - 将范围保存在 VBA 中的变量中以用于多个文件