【问题标题】:Mongodump query errorMongodump 查询错误
【发布时间】:2015-04-06 06:38:43
【问题描述】:
mongodump --username user --password password --db db --collection collection --query '{$and: [{"id": "ABCD"}, {"sz": {$gt: NumberLong(100)}}]}' --out dump

执行时,mongodump 抱怨:

assertion: 16619 code FailedToParse: FailedToParse: Bad characters in value: offset:63

如果我转义 $and$gt 子句:

mongodump --username user --password password --db db --collection collection --query '{\$and: [{"id": "ABCD"}, {"sz": {\$gt: NumberLong(100)}}]}' --out dump

它会抱怨

assertion: 16619 code FailedToParse: FailedToParse: First character in field must be [A-Za-z$_]: offset:1

此查询在mongodb shell 上成功运行,我不明白为什么我不能将它用作mongodump 中的--query 参数。

【问题讨论】:

    标签: mongodb mongodump


    【解决方案1】:

    在我看来,您的 $and 子句是不需要的。 {a: 'a', b: 'b'}$and : [{a: 'a'}, {b: 'b'}] 相同。

    你也不需要使用"id",你可以写idNumberLong也一样。

    所以我会把它改写为... --query '{id: "ABCD", sz: {$gt: 100}}' --out dump,这样可以工作(如果你在单引号中,你不要转义 $)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-28
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多