I am trying to export data using mongoexport and specific query. Query just filters records in specific column “op”.
Below is the query and command I am using.
C:\mongo\bin\mongoexport --host Hostname --port 999 -u user -p user --authenticationDatabase admin --db logsadmin --collection userActivity20201119 --query ‘{ op: “LookupAdvancedLaneMakers”}’ --out E:\ALM\UserActivity\userActivity.json
2020-12-01T04:46:47.859-0800 too many positional arguments: [op: LookupAdvanc
edLaneMakers}']
2020-12-01T04:46:47.860-0800 try ‘mongoexport --help’ for more information
steevej
(Steeve Juneau)
December 1, 2020, 1:04pm
2
If you look at the documentation at mongoexport — MongoDB Manual you will see you are missing the equal sign between argument keys and values.
2 Likes
Hi Steeve,
Thanks for the reply. This command work when I remove query part. I also tried using equal sing. I am getting same error.
Try double quotes after query instead of single quote and also enclose --out path in quotes
1 Like
Hi @Ashish_Kulkarni , you will need to escape the "
characters in the --query
option with a backslash \
. The following will work on powershell:
--query '{ op: \"LookupAdvancedLaneMakers\"}'
As Ramachandra alluded to, on cmd.exe, you can’t use single quotes, so you would have to do the following (which also works on powershell):
--query "{ op: \"LookupAdvancedLaneMakers\"}"
Having an equals or space between options and option arguments makes no difference. --foo=bar
is equivalent to --foo bar
.
2 Likes