odejs mongodb的Transaction API`withTransaction`始终返回null
odejs mongodb的Transaction API`withTransaction`始终返回null
我想从mongodb的withTransaction函数返回某些结果。但是,我似乎只返回了null。官方文档中记录了应返还诺言。./api/ClientSession.htmlIMPORTAT: This method requires the user to return a P
odejs mongodb的Transaction API`withTransaction`始终返回null
我想从mongodb的withTransaction
函数返回某些结果。但是,我似乎只返回了null。
官方文档中记录了应返还诺言。
./api/ClientSession.html
IMPORTAT: This method requires the user to return a Promise, all lambdas that do not return a Promise will result in undefined behavior.
index.js
由于异步函数总是返回Promise。我用一个简单的字符串替换了ct mongodb = require('mongodb'); (async() => { ct client = await (url); ct db = await client.db("testt"); ct session = client.startSession() ct res = session.withTransaction(async function() { return new Promise((resolve, reject) => { if(true) { resolve('laughed') } else { reject(`not laughing`); } }) }) cole.log('result here') //result here cole.log(res) //Promise { <pending> } cole.log(await res); //null }) ()
编辑:
new Promise()
,但是结果却完全一样,这很令人困惑。回答如下:ct res = session.withTransaction(async function() { return `laughed` })
我想从mongodb的withTransaction函数返回某些结果。但是,我似乎无法返回任何东西,除了null之外。官方文档中记录了...
官方文档中记录了应返还诺言。
#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
上传时间: 2024-05-07 12:13:11
推荐阅读
留言与评论(共有 10 条评论) |
本站网友 石兆彬 | 3分钟前 发表 |
官方文档中记录了应返还诺言 | |
本站网友 虎门租房网 | 12分钟前 发表 |
本站网友 室间隔缺损 | 3分钟前 发表 |
all lambdas that do not return a Promise will result in undefined behavior. index.jsct mongodb = require('mongodb'); (async() => { ct client = await (url); ct db = await client.db("testt"); ct session = client.startSession() ct res = session.withTransaction(async function() { return new Promise((resolve | |
本站网友 武汉女王 | 16分钟前 发表 |
但是 | |
本站网友 东戴河新区 | 19分钟前 发表 |
除了null之外 | |
本站网友 第112届广交会 | 11分钟前 发表 |
官方文档中记录了应返还诺言 | |
本站网友 石家庄市游泳馆 | 23分钟前 发表 |
reject) => { if(true) { resolve('laughed') } else { reject(`not laughing`); } }) }) cole.log('result here') //result here cole.log(res) //Promise { <pending> } cole.log(await res); //null }) () 编辑:由于异步函数总是返回Promise | |
本站网友 阴沉木是什么 | 1分钟前 发表 |
但是 | |
本站网友 java交流 | 1分钟前 发表 |
reject) => { if(true) { resolve('laughed') } else { reject(`not laughing`); } }) }) cole.log('result here') //result here cole.log(res) //Promise { <pending> } cole.log(await res); //null }) () 编辑:由于异步函数总是返回Promise |