mongodb - mongoexport using subprocess failed -
i have been trying export csv mongodb, using python's subprocess module. however, spacing in file path hindering me exporting correctly.
this works in windows cmd if input/output script lies. so, there no need specify path.
mongoexport --db wsg-database --collection wsg --type=csv --fieldfile fields.txt --out export.csv if specify path below, gives syntax error:
subprocess.call("mongoexport --db test-database --collection wsg --type=csv --fieldfile "c:\users\jess teo\desktop\fields.txt" --out "c:\users\jess teo\desktop\export.csv"", shell=true) using list form of subprocess gives out empty file.
subprocess.call(["mongoexport", "--db", "test-database", "--collection", \ "wsg", "--type=csv", "--fieldfile", \ "c:\users\jess teo\desktop\fields.txt",\ "--out", "c:\users\jess teo\desktop\export.csv"]) any ideas?
thank you!
silly me, colleague has advised simple resolution. add "r" @ beginning of command, double quotes around file path , work.
subprocess.call(r'mongoexport --db test-database --collection wsg --type=csv --fieldfile "c:\users\jess teo\desktop\fields.txt" --out "c:\users\jess teo\desktop\export.csv"', shell=true)
Comments
Post a Comment