mongodb V4.0.9 开启复制集
初始化复制集配置
rs.initiate({ "_id": "myreplset", "members": [ { "_id": 0, "host": "127.0.0.1:27017" }, { "_id": 1, "host": "127.0.0.1:27018" }, { "_id": 2, "host": "127.0.0.1:27019" } ] })
# 开启会话session1 = db.getMongo().startSession( { readPreference: { mode: "primary" } } ); # 关闭session1.endSession();
session1.startTransaction();session1.abortTransaction();session1.commitTransaction();
session1.getDatabase("db1").users.updateOne( { username: "klinson" }, { $set: { sex: 1 } } );session1.getDatabase("db1").orders.updateOne({order_number:"2019121300001"}, {$set:{price: 250}})session1.getDatabase("db1").users.find( { username: "klinson" } );session1.getDatabase("db1").users.delete( { username: "test1" } );