Gustavo Silva Costa
Gustavo Silva Costa

Reputation: 53

Script Dump mongodb

I've this script

for col in "${COLLECTIONS[@]}";
do
    mongodump --gzip --db $db --collection $col --query $QUERY --archive=/tmp/bkpmongodev/$db-$col-$FOLDER.gz
done

and when i run it, i get this error:

positional arguments not allowed: [_id : { $gt : ObjectId("61b1eca70000000000000000") }}']

and when i do echo the command and i past it in terminal, it work

echo "mongodump --gzip --db $db --collection $col --query $QUERY --archive=/tmp/bkpmongodev/$db-$col-$FOLDER.gz"

Upvotes: 0

Views: 287

Answers (1)

Gustavo Silva Costa
Gustavo Silva Costa

Reputation: 53

the error occurred because of spaces between strings in $QUERY

Before:

QUERY=" { \"_id\" : { \"\$gt\" : ObjectId(\"$stringObjectId\") } } "

Now:

QUERY="{_id:{\$gt:ObjectId(\"$stringObjectId\")}}"

Upvotes: 0

Related Questions