Reputation: 17491
mongodump --username user --password password --db db --collection collection --query '{$and: [{"id": "ABCD"}, {"sz": {$gt: NumberLong(100)}}]}' --out dump
When executed, mongodump
complained with:
assertion: 16619 code FailedToParse: FailedToParse: Bad characters in value: offset:63
If I escape the $and
and $gt
clauses:
mongodump --username user --password password --db db --collection collection --query '{\$and: [{"id": "ABCD"}, {"sz": {\$gt: NumberLong(100)}}]}' --out dump
It will instead complain with
assertion: 16619 code FailedToParse: FailedToParse: First character in field must be [A-Za-z$_]: offset:1
This query runs successfully on mongodb
shell, I can't see why I can't use it as a --query
parameter in mongodump
.
Upvotes: 0
Views: 1662
Reputation: 222531
In my opinion your $and clause is not needed.
{a: 'a', b: 'b'}
is the same as $and : [{a: 'a'}, {b: 'b'}]
.
You also do not need to use "id"
, you can just write id
, the same for NumberLong
.
So I would rewrite it as ... --query '{id: "ABCD", sz: {$gt: 100}}' --out dump
which works (you do not to escape $ if you are in a single quotes).
Upvotes: 2