On this page本页内容
Session
The Session object for the connection in mongosh. mongosh中连接的会话对象。To instantiate a session for the connection in 要在mongosh, see Mongo.startSession(). mongosh中为连接实例化会话,请参阅Mongo.startSession()。For more information on sessions, see Client Sessions and Causal Consistency Guarantees.有关会话的更多信息,请参阅客户端会话和因果一致性保证。
Session.getDatabase(<database>) | mongosh.mongosh中的会话访问指定的数据库。 |
Session.advanceClusterTime({ clusterTime: <timestamp>, signature: { hash: <BinData>, keyId: <NumberLong> } }) | |
Session.advanceOperationTime(<timestamp>) | |
Session.endSession() | |
Session.hasEnded() | |
Session.getClusterTime() | |
Session.getOperationTime() | |
Session.getOptions() | SessionOptions().SessionOptions()。
|
Session.startTransaction() | Session.startTransaction().Session.startTransaction()。
|
Session.commitTransaction() | Session.commitTransaction().Session.commitTransaction()。
|
Session.abortTransaction() | Session.abortTransaction().Session.abortTransaction()。
|
The following example starts a session on the 以下示例在与Mongo() connection object associated with mongosh's global db variable, and then uses the Session.getDatabase() method to retrieve the database object associated with the session.mongosh的全局db变量关联的Mongo()连接对象上启动会话,然后使用Session.getDatabase()方法检索与会话关联的数据库对象。
var session = db.getMongo().startSession();
db = session.getDatabase(db.getName());