We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return await Article.findOne({ _id: articleId, book, uuid }).session(session);
"MongoError: Read preference in a transaction must be primary, not: secondary
The text was updated successfully, but these errors were encountered:
@naxiaoguang 时间太久了,不好意思,一直没有时间 今天测试了下
const mongoose = require('mongoose') const Acid = require('mongoose-acid') const os = require('os') const hostname = os.hostname() mongoose.set('debug', false) Acid.set('debug', false) const uri = os.platform() === 'win32' ? `mongodb://${hostname}:27017,${hostname}:27018,${hostname}:27019/test` : 'mongodb://localhost:27017,localhost:27018,localhost:27019/test' let conn const Account = mongoose.model('Account', new mongoose.Schema({ balance: Number })) const People = mongoose.model('People', new mongoose.Schema({ name: String, balance: Number })) async function test() { let conn = await mongoose.connect(uri, { replicaSet: 'rs', useUnifiedTopology: true, useNewUrlParser: true }) // await new Account({ balance: 300 }).save() await Acid(async (session) => { let account = await Account.findOne({ _id: '5e1438aef13bc455b07bf22d' }).session(session) account.balance += 300 await account.save() await new People({ balance: account.balance }).save({ session }) throw new Error('THROW ERROR') }) await conn.disconnect() } test()
并没有发现你出现的问题,你的问题应该和这个库没有关系,应该是你mongodb连接的配置问题?
Sorry, something went wrong.
看下这些副本集连接的配置,确定下您的问题吧
No branches or pull requests
return await Article.findOne({ _id: articleId, book, uuid }).session(session);
"MongoError: Read preference in a transaction must be primary, not: secondary
The text was updated successfully, but these errors were encountered: