代码之家  ›  专栏  ›  技术社区  ›  Aquarius_Girl

如何解决MongoDB查询括号错误?

  •  0
  • Aquarius_Girl  · 技术社区  · 6 年前
    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可以用来编写这些查询?

    0 回复  |  直到 6 年前
        1
  •  1
  •   Valijon    6 年前

    试试这个:

    db.restaurants.find({
      $or: [
        {
          $and: [
            {
              cuisine: {
                $ne: "American"
              }
            },
            {
              cuisine: {
                $ne: "Chinese"
              }
            }
          ]
        },
        {
          name: /^Wil/
        }
      ]
    },
    {
      name: 1,
      cuisine: 1
    })
    

    MongoPlayground

    MongoPlayground .
    对于更复杂的查询,我通常使用 Robo3t / Studio3t .

    推荐文章