Mongodump Error : positional arguments not allowed: [abc] - mongodb

The below comment throwing this error for mongodump
mongodump --host xx.xxx.xx.xxx -db abc --out home/dataBaseBackup/

You have missed an -. The correct one is given below:
mongodump --host xx.xxx.xx.xxx --db abc --out home/dataBaseBackup/

Related

Build a mongo container and import data

I want to build a Mongo container, and insert some data stored in the folder /mongo_mock_data in this container. Here are my lines of code:
MONGO_ID=$(docker run --publish-all -d --mount type=bind,source=${PWD}/mongo_mock_data,target=/tmp/mongo_mock_data mongo)
MONGO_PORT=$( docker inspect $MONGO_ID | jq -r '.[0].NetworkSettings.Ports."27017/tcp"[0].HostPort' )
MONGODB_URL=mongodb://localhost:${MONGO_PORT}
docker exec $MONGO_ID mongoimport --host $MONGODB_URL --db algo --collection train --type json --file /tmp/mongo_mock_data/train_data.json --jsonArray
docker exec $MONGO_ID mongoimport --host $MONGODB_URL --db algo --collection calculation --type json --file /tmp/mongo_mock_data/predict_data.json --jsonArray
docker exec $MONGO_ID mongoimport --host $MONGODB_URL --db algo --collection train --type json --file /tmp/mongo_mock_data/cluster_data.json --jsonArray
I have the following error:
error parsing command line options: error parsing URI from mongodb:///localhost:32773/?replicaSet=mongodb:: error parsing uri: must have at least 1 host
any ideas what Im doing wrong?
EDIT:
If I try:
MONGODB_URL=localhost:${MONGO_PORT}
docker exec $MONGO_ID mongoimport --host $MONGODB_URL --db pulse_algo --collection train --type json --file /tmp/mongo_mock_data/train_data.json --jsonArray
instead of
MONGODB_URL=mongodb://localhost:${MONGO_PORT}
docker exec $MONGO_ID mongoimport --host $MONGODB_URL --db algo --collection train --type json --file /tmp/mongo_mock_data/train_data.json --jsonArray
I have the following error:
error connecting to host: could not connect to server: server selection error: server selection timeout
Is the third slash in mongodb:/// a transcription error? If not, then what is happening is that MongoDB is trying to connect to a server at '' (ie, nothing) to a database named localhost:32773, rather than a server at localhost:32773 & the default database.
So, finally, I solved my issue by dropping the argument --host:
MONGO_ID=$(docker run --publish-all -d --mount type=bind,source=${PWD}/mongo_mock_data,target=/tmp/mongo_mock_data mongo)
MONGO_PORT=$( docker inspect $MONGO_ID | jq -r '.[0].NetworkSettings.Ports."27017/tcp"[0].HostPort' )
docker exec $MONGO_ID mongoimport --db algo --collection train --type json --file /tmp/mongo_mock_data/train_data.json --jsonArray
docker exec $MONGO_ID mongoimport --db algo --collection calculation --type json --file /tmp/mongo_mock_data/predict_data.json --jsonArray
docker exec $MONGO_ID mongoimport --db algo --collection train --type json --file /tmp/mongo_mock_data/cluster_data.json --jsonArray
In my case, I was getting this error because of passing option --csv instead of --type=csv to mongoexport. Correction of that fixed this issue.
mongoexport type options
Error message could've been better.

Mongorestore in docker failed: Failed: gzip: invalid header

I created a mongo dump with commands (as suggested in this answer)
docker exec -it mongodb bash
mongodump --host $cluster --ssl --username $username --authenticationDatabase admin --db $dbname --gzip --archive > dumpname.gz
Now when I'm trying to restore the dump with
docker exec mongodb bash -c 'mongorestore --gzip --archive=dumpname.gz'
I get
Failed: gzip: invalid header
It seems like there is some bug with using redirection (>). So when I changed the first command to not use it, mongorestore started to work:
mongodump --host $cluster --ssl --username $username --authenticationDatabase admin --db $dbname --gzip --archive=dumpname.gz
Some similar problems could be found here

mongorestore fails due to invalid BSONSize

I have a script which dumps a mongodb
mongodump --archive=$MONGODB_PATH --host $MONGODB_HOST --port $MONGODB_PORT --username $MONGODB_USER --password $MONGODB_PASS --db $MONGODB_NAME
but when I try to restore it with
mongorestore -d db_name backup/dump
it fails with:
Failed: dump_name: error restoring from backup/dump/dump_name: reading bson input: invalid BSONSize: -2120621459 bytes
I tried --batchSize=100 but it didn't solve the issue for me.
What's going wrong here?
Solution was: mongorestore --archive=backup/dump
When you dump with --archive flag you must restore with --archive flag as well.

mongodump 3.2.1 positional arguments not allowed

trying mongodump with following options and get "positional arguments not allowed"
mongodump --host=hostname --port=27017 --db=db --out=/path --oplog --gzip
tried mongodump -h hostname -d dbname and that works
What does the message
positional arguments not allowed
mean?
You got the syntax wrong in the first one. You need to remove the = sign. See documentation.
mongodump --host hostname --port 27017 --db db --out /path --oplog --gzip
mongodump -d<dbname> -o <backUpPath>
like this:
mongodump -d projectdb -o /Users/zhangzhanqi/Desktop/backup_mongo/aaa
The syntax has been changed to replacement of = with space character in front of the argument names. To clear the point with a descriptive answer, I put two general forms with long argument and short argument names.
Long parameter form:
mongodump --host hostname --port 27017 --db db --out /path --oplog --gzip
Short parameter form:
mongodump -h hostname -p 27017 -d db -o /path --oplog --gzip
You can find more explanation and examples in the following link:
https://docs.mongodb.com/manual/reference/program/mongodump/

unexpected identifier error while bulk insert into mongodb

I have a json file and am trying to insert in bulk to mongodb
I do
mongoimport --host localhost --db testdb --collection testdbjson --username user -- password pass --type json --file /home/pet/mng/json_test.json
It gives the following error
SyntaxError: Unexpected identifier
Please help!
the document mongoimport the correct syntax
mongoimport -host 127.0.0.1 -port 27017 -u user -p pass -collection testdbjson --db testdb --file /home/pet/mng/json_test.json
or
mongoimport -host 127.0.0.1:27017 -u user -p pass -collection testdbjson --db testdb --file /home/pet/mng/json_test.json
I had the exact same error now - I figured it out. I think you have connected to your mongo instance on mongolab first before you wanted to import.
You must not connect to mongolab first - disconnect by typing in "exit" in the shell to get back to command prompt. Then issue the mongoimport command again, the import should work this time.