I just moved to a new laptop which had mongo 3.0.0 I believe. On the new laptop I have mongo 3.0.4. and trying the script that was working on the old laptop is giving me errors
I think giving a white spaces in the file name of directory will also contribute to this error.
If you get this error while inserting fields with --fields, the probable reason might be you are using spaces to do that.
Both -f and --fields should work in those cases Using Mongo Version 3.0.6
mongoimport --db logs --collection action_logs --type tsv -f updated_at ,transaction_time ,origin --file parsed.tsv
mongoimport --db logs --collection action_logs --type tsv -f updated_at,transaction_time,origin --file parsed.tsv
This error can also occur if white spaces are given without a "\" in the path to the file . Ex: This wont work:
But this would work :
None of the above mentioned answers solved my problem but they indeed helped me in figuring out what I was doing wrong.(I am using windows)
1)using -d instead of --d (shorthand only require one - not two --)
2)using "" for absolute file path.
3)Changing \ to / in file path location.
For example my files location in windows is:
C:\kp github\other projects\projectXyz\myFile.csv
So for me the command that worked was:
mongoimport -d users -c contacts --type=csv --headerline --file="C:/kp github/other projects/projectXyz/myFile.csv"
or
mongoimport -d users -c contacts --type csv --headerline --file "C:/kp github/other projects/projectXyz/myFile.csv"
where users is my db name and contacts is my collection name
If you are getting mongodb-error
validating settings: only one positional argument is allowed.
2.use / instead of \ in --file path.
For example:
Suppose you are trying to import data from your local machine to server (MongoDB Atlas or your MongoDB server or locally) in your collection then follow this:
mongoimport --host "cluster0-shard-00-01-ceax1.mongodb.net:27017" --db <dbname> --type json --file "C:/Users/ranjeet/Downloads/MongoDb project/ranjeet.json" --authenticationDatabase admin --ssl --username <Username> --password <Password> --collection <CollectionName>
Just a wild guess...
... but the various long options should be specified using --
, not -
:
mongoimport --host localhost \
--db roudy123_q \
--collection LebaneseAmericanUniversity\(Lebanon\).json \
--file LebaneseAmericanUniversity\(Lebanon\).json \
--jsonArray
Maybe this particular version of mongoimport
is more punctilious about that, and will treat -db ... -collection ...
as positional arguments rather than keyword arguments ?