Question: I'm trying to import a json file with the command : `mongoimport -c collection -d db < file.json`. When I call this command from the shell, every documents are imported. However, when I try to call it from a python script with the module subprocess like this : `subprocess.call('mongoimport -c collection -d db < file.json', shell=True)`, I have the following error: `Failed: error processing document #37: unexpected EOF`. Can someone explain me why does it work with the shell but not when it is called from the script please?

Thanks in advance.

Answer: 
I thing is because subprocess.Popen constructor accepts list of args, not string, like this:

```
p = subprocess.Popen(['mongoimport', '--db', 'AutoPrivilege', '-c','cars', 'stockvo.json', '--jsonArray', '--upsert','--drop'])...

```
You can use os command:

```py
for dump_file in dumped_files:
    collection_name = dump_file.split('/')[-1].split('.')[0]
    # Restoring collection
    os.system(f'mongoimport --host {host} -d {database} --port {port} --collection {collection_name} --file {backup_file} --jsonArray --upsert')

```