Search code examples
jsonmongodbmongodb-querymongoexport

mongoexport fails when I add --collection BrowserHistory


I am trying to mongoexport a collection named,BrowserHistory from my DB. I have tried doing this through SSH into my CentOS server and a local MongoDB install on my computer. I have MongoDB 2.6 installed.

Note: I have obscured the server, etc. info

The commands I have tried and results are below:

 mongoexport --host host.xysz.com:27017 --username iamuser2 --password securepass --db test1ng1 --collection BrowserHistory --out ram.json

Result: "Error parsing command line: too many positional options have been specified on the command line try 'mongoexport --help' for more information"

mongoexport --host host.xysz.com:27017 --username iamuser2 --password securepass --db test1ng1 --out ram.json

Result: connected to: host.xysz.com:27017 no collection specified! Export MongoDB data to CSV, TSV, or JSON files.

I need to output the collection into json file(s) so I can import it into Hive.


Solution

  • Looks like the 'collection' parameter value has whitespace. This can be overcome by enclosing it in single quote.

    mongoexport --host host.xysz.com:27017 --username iamuser2 --password securepass --db test1ng1 --collection 'BrowserHistory' --out ram.json