源代码如下:
init(db){
this.db = db
}
async getDocument(colletion,document){
let dd
let that = this
try {
dd = await that.db.collection(colletion).doc(document).get()
console.log('读取数据库:集合:' + colletion + ',记录:'+document+'成功:'+dd)
return dd.data
} catch (e) {
console.error('读取数据库错误:' + e + '集合:' + colletion + ',记录:'+document)
return undefined
}
}
async setDocument(colletion,document,data){
let dd
let that = this
try {
dd = await that.db.collection(colletion).doc(document).set({data: data})
console.log('修改数据库:集合:' + colletion + ',记录:'+document+'成功:')
return dd
} catch (e) {
console.error(e)
console.log('修改数据库错误(集合,记录,数据):', colletion, document,data)
return undefined
}
}
async addDocument(colletion,document,data){
let that = this
data._id = document
try{
await that.db.collection(colletion).add({ //建立currentFlow
data: data
})
return 'SUCCESS'
}catch(e){
console.error(e)
console.log('数据库增加数据错误(集合,记录,数据):', colletion, document,data)
return 'FAIL'
}
}
}
但是云端都没报错,在本地调试频繁报错:
document.get:fail -501001 resource system error. ESOCKETTIMEDOUT
Your current request database.getDocument is longer than 3s, it may be due to the network or your query performance | [17e84cdf8bb_31]
(anonymous) @ httpRequest.js:133
listOnTimeout @ internal/timers.js:549
processTimers @ internal/timers.js:492
Timeout (async)
init @ internal/inspector_async_hook.js:25
emitInitNative @ internal/async_hooks.js:144
emitInitScript @ internal/async_hooks.js:346
initAsyncResource @ internal/timers.js:153
Timeout @ internal/timers.js:186
setTimeout @ timers.js:146
setSlowWarning @ httpRequest.js:128
exports.default @ httpRequest.js:371
send @ dbRequest.js:31
get @ document.js:182
(anonymous) @ index.js:1274
get @ index.js:1270
getDocument @ Database.js:13
_getFromDB @ index.js:162
exports.main @ index.js:85
(anonymous) @ node.js:1
processTicksAndRejections @ internal/process/task_queues.js:97
Promise.then (async)
(anonymous) @ node.js:1
emit @ events.js:328
endReadableNT @ _stream_readable.js:1201
processTicksAndRejections @ internal/process/task_queues.js:84
TickObject (async)
init @ internal/inspector_async_hook.js:25
emitInitNative @ internal/async_hooks.js:144
emitInitScript @ internal/async_hooks.js:346
nextTick @ internal/process/task_queues.js:135
endReadable @ _stream_readable.js:1190
Readable.read @ _stream_readable.js:420
flow @ _stream_readable.js:979
emitReadable_ @ _stream_readable.js:572
onEofChunk @ _stream_readable.js:536
readableAddChunk @ _stream_readable.js:253
Readable.push @ _stream_readable.js:214
parserOnMessageComplete @ _http_common.js:150
HTTPINCOMINGMESSAGE (async)
init @ internal/inspector_async_hook.js:25
emitInitNative @ internal/async_hooks.js:144
connectionListenerInternal @ _http_server.js:423
defaultTriggerAsyncIdScope @ internal/async_hooks.js:313
connectionListener @ _http_server.js:399
emit @ events.js:316
onconnection @ net.js:1558
这些现象之前不频繁出现。直到去年底升级新版本后频繁出现!!
做了以下措施都失败:
1.回退到21年2月份的开发者工具版本;
2.把wx-server-sdk包重新安装
3.把后台响应时间从10秒变成60秒
wifi和移动流量都超时?