정의
Mongo.startSession(<options>)Starts a session for the connection.
mongoshassigns the session ID to commands associated with the session.중요
Mongo쉬 방법
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.데이터베이스 명령에 대해서는
startSession명령을 참조하십시오.MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 설명서를 참조하세요.
세션은 세션을 생성한
MongoClient객체에만 사용할 수 있습니다. 단일 세션은 동시에 사용할 수 없습니다. 단일 세션을 사용하는 작업은 순차적으로 실행해야 합니다.The
startSession()method can take a document with session options. The options available are:필드설명causalConsistency
Boolean. Enables or disables causal consistency for the session.
Mongo.startSession()enablescausalConsistencyby default.세션을 시작한 후에는
causalConsistency설정을 수정할 수 없습니다.Mongo()연결 객체의 인과적 일관성이 비활성화되었거나 그 반대의 경우에도 세션에서는 인과적 일관성이 활성화되었을 수 있습니다. 연결 객체에 인과적 일관성을 설정하려면Mongo.setCausalConsistency()를 참조하세요.readConcern
문서입니다. 읽기 고려를 지정합니다.
세션을 시작한 후 설정을 수정하려면
Session.getOptions().setReadConcern()을 참조하세요.읽기 설정
문서입니다. 읽기 설정을 지정합니다.
읽기 설정 문서에는
mode필드와 선택 사항인tags필드가 포함되어 있습니다.{ mode: <string>, tags: <array> } 세션을 시작한 후 설정을 수정하려면
Session.getOptions().setReadPreference()을 참조하세요.retryWrites
부울입니다. 일시적인 네트워크 오류 발생 시 쓰기를 재시도하는 기능을 활성화하거나 비활성화합니다.
If you start
mongoshwith the--retryWritesoption,retryWritesis enabled by default forMongo.startSession().세션을 시작한 후에는
retryWrites설정을 수정할 수 없습니다.쓰기 고려
문서입니다. 쓰기 고려를 지정합니다.
세션을 시작한 후 설정을 수정하려면
Session.getOptions().setWriteConcern()을 참조하세요.
예시
The following starts a session with causal consistency and retryable writes enabled on the Mongo() connection object associated with mongosh's global db variable:
db = db.getMongo().startSession({retryWrites: true, causalConsistency: true}).getDatabase(db.getName());