mongodb - how to use mongodbexport in python or shell script -


i want create json output mongodb mongodbexport

it act correctly in terminal command :

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

but how can use in shell script or in python subprocess.call

i use code in python :

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

but create error: "no collection specified!" ,"export mongodb data csv, tsv or json files."

thank

if passing arguments in via list, need remove shell = true argument, otherwise first element of list used construct subprocess call (in case mongoexport called)

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

you use shell = true when you're passing command string not list

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

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -