假设数据表中存放一个document
{
"num": 0
}
请求一次接口, 则调用mongoose,让num+1
请求1000次
const axios = require('axios');
for (let i = 0; i < 1000; i++) {
(i => {
axios
.get(
'http://localhost:3000/test/update/0f9c4a32-6170-402b-828f-8e81b398dfb1'
)
.then(data => {
console.log(`${i}: ${data.data.num}`);
})
.catch(function(err) {});
})(i);
}
718: 3 743: 3 768: 3 793: 3 818: 3 843: 3 868: 3 893: 3 918: 3 943: 3 968: 3 993: 3 957: 3 982: 3 946: 3 947: 3 972: 3 997: 3
可以看到,结果并不像相信中的数字
而nodejs也没有进程锁,求解?
这是mongodb的特性,还是mongosse的?
参考: https://github.com/Automattic/mongoose/issues/4004 https://github.com/Automattic/mongoose/issues/5424