Mongoexport error: “too many positional options”

Had a quick task where I needed to export results of a mongo query into a CSV file.

Mongoexport command comes in very handy in this case.

I constructed my query:

mongoexport -h myhost.mongolab.com:PORT -d mydb -u myusername -p mypassword 
-c coll_name -q {tag:/mytagname/,count:{$gte:10}} -f tag,tag_date,count 
--csv -o test.csv

And when I ran it, got this error “too many positional options”

Some google groups suggest that you need to remove the space between -p and password, but it was actually fixed in the latest version.

The problem was caused by the lack quotes around my query – they need to be there. So the correct one looks like this:

mongoexport -h myhost.mongolab.com:PORT -d mydb -u myusername -p mypassword
-c coll_name -q '{tag:/mytagname/,count:{$gte:10}}' -f tag,tag_date,count 
--csv -o test.csv

Also, “-f” values (for field names) need to be comma-separated, no spaces.

Advertisements

2 thoughts on “Mongoexport error: “too many positional options”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s