Mongodump 查询错误
Mongodump query error
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
参数。
我认为您的 $and 子句是不需要的。
{a: 'a', b: 'b'}
等同于 $and : [{a: 'a'}, {b: 'b'}]
.
你也可以不用"id"
,直接写id
即可,NumberLong
也一样。
所以我将其重写为 ... --query '{id: "ABCD", sz: {$gt: 100}}' --out dump
有效(如果你在单引号中,则不要转义 $)。
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
参数。
我认为您的 $and 子句是不需要的。
{a: 'a', b: 'b'}
等同于 $and : [{a: 'a'}, {b: 'b'}]
.
你也可以不用"id"
,直接写id
即可,NumberLong
也一样。
所以我将其重写为 ... --query '{id: "ABCD", sz: {$gt: 100}}' --out dump
有效(如果你在单引号中,则不要转义 $)。