윈도우 환경의 몽고 DB에 자료 업로드 할 때 권한설정 오류

윈도우 환경의 몽고 DB에 자료 업로드 할 때 권한설정 오류

728x90

window 7 환경에서

csv파일을 플라스크 환경에서 mongodb에 일괄 저장하고자 할 때

@app.route('/datacheck') def datacheck(): data_path = "static/data/테스트자료1.csv" print(data_path) df =pd.read_csv(data_path, encoding="CP949") json_str = df.to_json(orient="records") print(type(json_str)) json_data = json.loads(json_str) for jd in json_data: print(jd) db.csv_json.insert_one(jd) return render_template('datacheck.html', json_data=json_data)

다음과 같은 오류가 발생한 경우

pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0.0, 'errmsg': 'Authentication failed.', 'code': 18, 'codeName': 'AuthenticationFailed'}

해결책은

몽고DB에 로그인하는 권한 설정의 문제를 해결하면 된다

어떻게 하느냐는

일단 몽고DB를 설치할 때 지정한 저장폴더로 이동한다.

여기서는 c:\mongodata\db를 지정한 경우이다.

이 폴더에 접근해서 mongod.cfg 파일을 열고

다음 mongod.cfg 파일 내용 중에서 #security: 부분을 추가한다.

security: authorization: "enabled"

# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: C:\mongodata\db\data journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: C:\mongodata\db\log\mongod.log # network interfaces net: port: 27017 bindIp: 127.0.0.1 #processManagement: #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:

728x90

반응형

from http://ecogis.tistory.com/159 by ccl(A) rewrite - 2021-08-25 00:00:04