Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb import error using makefile

Tags:

mongodb

I'm trying to use mongoimport to import multiple collections. I do that in a .sh file "seed.sh" which contains the following :

mongoimport --db blog --collection users --file ./db/users.json --jsonArray
mongoimport --db blog --collection articles --file ./db/articles.json --jsonArray

I use makefile in cygwin64 terminal. The first import always fails. The second always succeeds. This holds true if I change the order of the collection that is being imported. I receive the error "Error parsing command line: unknown option jsonArray". What is the problem here?

like image 284
user3619165 Avatar asked Dec 01 '25 14:12

user3619165


2 Answers

The problem is that your seed.sh file currently has CRLF line ending. Convert to LF line ending for seed.sh to work properly.

like image 66
qminhdo Avatar answered Dec 04 '25 06:12

qminhdo


The problem is because of CR LF and LF characters line ending. Windows uses CR LF while Unix uses LF. Now changing those two lines of yours to mongoimport --db blog --collection users --file ./db/users.json --jsonArray && mongoimport --db blog --collection articles --file ./db/articles.json --jsonArray will probably solve your problem.

for more information about line endings please refer to this stackoverflow post.

like image 42
MajidJafari Avatar answered Dec 04 '25 05:12

MajidJafari