从python实现mongorestore时,系统找不到指定的路径

2024-05-02 17:00:42 发布

您现在位置:Python中文网/ 问答频道 /正文

使用以下代码将mongodump从云恢复到我的本地服务器:

    import subprocess
    address_of_mongodump = 'C:/Users/Lenovo/Documents/home/ubuntu/dump2020'
    collection = ['mongorestore', '--uri', 'mongodb://localhost:27017', f'--archive {address_of_mongodump}']
    data=subprocess.run(collection, shell = True,capture_output=True)

获取以下错误:

CompletedProcess(args=['mongorestore', '--uri', 'mongodb://localhost:27017', '--archive=C:/Users/Lenovo/Documents/home/ubuntu/dump2020'], returncode=1, stdout=b'', stderr=b'2021-01-06T12:01:37.580+0530\tFailed: open C:\Users\Lenovo\Documents\home\ubuntu\dump2020\archive: The system cannot find the file specified.\n2021-01-06T12:01:37.583+0530\t0 document(s) restored successfully. 0 document(s) failed to restore.\n')

我尝试在anaconda提示符下使用mongorestore命令,它成功地从同一位置恢复了所有文件,但我无法使用python(在jupyter中)执行同样的操作


Tags: ofhomeaddressubuntumongodburiusersdocuments