Giter VIP home page Giter VIP logo

Comments (2)

dtboy1995 avatar dtboy1995 commented on May 18, 2024

@naxiaoguang 时间太久了,不好意思,一直没有时间
今天测试了下

环境

  • run-rs 4.2.0
  • Windows10
  • Node 12.14.0

代码

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连接的配置问题?

from mongoose-acid.

dtboy1995 avatar dtboy1995 commented on May 18, 2024

image
看下这些副本集连接的配置,确定下您的问题吧

from mongoose-acid.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.