猫鼬文档锁,该文档在事务提交时不会被其他人读取

时间:2019-01-24 05:22:37

标签: mysql node.js laravel mongoose

我正在尝试实现向客户多次登录发送凭证,如果两个用户同时登录并发送凭证,则两个用户访问同一凭证的发送凭证,如何实现一个用户读取另一个用户不能访问的凭证。

const mongoose = require(“ mongoose”)

    const {Transaction-manager}= require("mongodb-tx")  

    const mgr = new Transaction-manager({mongoose})  

    await mgr.transaction(async (t) => {  

    let voucher_Ids = await vouchers.find({ voucher_status: 'Created', status: true }, { _id: 1 },{transaction: t, lock: t.LOCK}).limit(issue.vouchers_count);

                console.log(voucher_Ids)

                if (!voucher_Ids) {

                    throw new Error("conditions not satisfied")

                }

                })

0 个答案:

没有答案