1

i want to create a json output from mongodb by mongodbexport

it act correctly in terminal by this command :

sudo mongoexport --db mydb --collection url_db --query '{"state": "processed"}' --out /mongodb_json/name.JSON

but how can i use it in a shell script or in a python by subprocess.call

i use this code in python :

call(["mongoexport", "--db","mydb","--collection","url_db","--query","'{\"state\": \"processed\"}'","--out ",outfile],shell=True)

but it create this error: "no collection specified!" ,"Export MongoDB data to CSV, TSV or JSON files."

thank you

1 Answer 1

4

If you are passing your arguments in via a list, you need to remove the shell = True argument, otherwise only the first element of the list is used to construct your subprocess call (in this case only mongoexport is called)

call(["mongoexport", "--db","mydb","--collection","url_db","--query","'{\"state\": \"processed\"}'","--out ",outfile])

You only use shell = True when you're passing your command as a string not a list

call("mongoexport --db mydb --collection url_db --query '{\"state\": \"processed\"}' --out " + outfile, shell=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.