-3
빌드 mongoimport 명령
collection = filename[:filename.find('.')]
working_directory = 'C:/Users/Anshuman Misra/Downloads/'
json_file = filename + '.json'
mongoimport_cmd = 'mongoimport -h 127.0.0.1:27017 ' + \
'--db ' + db_name + \
' --collection ' + collection + \
' --file ' + working_directory + json_file
가져 오기 전에 존재하는 경우 수집을 드롭 (즉, 다시 실행)
if collection in db.collection_names():
print 'Dropping collection: ' + collection
db[collection].drop()
을 실행 명령
print 'Executing: ' + mongoimport_cmd
subprocess.call(mongoimport_cmd.split())
subprocess.call을 호출하는 동안 shell = True를 추가했습니다. 코드는 작동하지만 출력이 잘못되었습니다. 즉, –
@AnshumanMisra, 내가 말하는 0 출력이 무엇인지 이해할 수 없습니다. 전체 프로그램의 종료 코드입니까? 그렇다면 프로그램이 제대로 실행되었음을 의미하므로 OK입니다. – Mixhab
예 종료 코드 및 컬렉션에서 데이터베이스를로드 할 때 값 0을 사용합니다. "Anshuman Misra"를 따옴표 안에 넣는 것은 아직도 doesnt 일이다. –