Mongo export command using file

Hi Team,

Is there any option in mongoexport to read the query from the file instead of hardcoded into --query parameter ?

mongoexport --host=“xxx:post” --db=dbname --pretty --collection=employee --query=’{"_id":{$in:[“12345”,“567879”,“112233”]}}’ --out=employee.json

My DB version as below.

I just looked at and it appears not. However, on Unix based OS you could do:

query=$( < File_With_The_Query )
mongoexport ... --query="$query" ...
1 Like

any example , we need to run from mongo shell.

You do not run mongoexport from mongo shell.

1 Like

@steevej : Thansk for the response, Is there any issue for mongexport on mongoshell, if yes what the command we should use to expot the data from shell.

@Imran_khan, run the mongoexport command directly from the terminal and NOT from the shell, it is supposed to be executed independently and it would not work inside the shell.

What are you trying to achieve? Where is the data coming from in the shell in the first place?

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like