정의
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. Mutually exclusive withsnapshot.세션을 시작한 후에는
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설정을 수정할 수 없습니다.스냅샷
부울. MongoDB 5.0+ 배포를 위한 세션의 스냅샷 읽기 를 활성화합니다.
causalConsistency와 상호 배타적입니다.쓰기 고려
문서입니다. 쓰기 고려를 지정합니다.
세션을 시작한 후 설정을 수정하려면
Session.getOptions().setWriteConcern()을 참조하세요.
호환성
이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스
참고
이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
예시
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());