Query fails with too many positional arguments

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

If you look at the documentation at https://docs.mongodb.com/v4.2/reference/program/mongoexport/ 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.

1 Like