[英]MongoDB Driver : MongoError: Cursor Not found, cursor id: 7820213409290816 in namespace: db_name.collection_name
我創建了一個 Nodejs API 服務器,它正在訪問 AWS mongodb(版本:3.6)。 當我調用一個 api(比如 api/lowest)時,它給了我完美的結果,沒有任何錯誤。 但是當我幾乎同時多次調用這個 API 時(15 個 API 調用),對於很少的 API 調用(3-7)它給出
MongoError: Cursor Not found, cursor id xxxxx
API代碼如下——
app.get('/lowest', async (req, res, next) => {
let url = 'mongodb://url';
let param1 = req.query.param1;
let param2 = req.query.param2;
let client = mongodb.MongoClient;
try {
client.connect(url, function (err, client) {
let db = client.db("db1");
let collection = db.collection('collection1');
let options = {
allowDiskUse: false,
timeout: false,
noCursorTimeout: true
};
// returns mongodb aggregation pipeline
let pipeline = helper.getLowestPipeline(param1, param2);
//Step 1: declare promise
let myPromise = () => {
return new Promise((resolve, reject) => {
collection.aggregate(pipeline, options).toArray(function (err, data) {
err
? reject(err)
: resolve(data);
});
});
};
//Step 2: async promise handler
let callMyPromise = async () => {
let result = await (myPromise());
client.close();
//anything here is executed after result is resolved
return result;
};
//Step 3: make the call
callMyPromise().then(function (result) {
res.send(JSON.stringify({"status": 200, "error": null, "response": result}));
});
});
} catch (e) {
client.close();
res.json({"status": 500, "error": e, "response": null});
res.end();
}
});
pm2 monit 結果如下:
MongoError: Cursor Not found, cursor id: 7820213409290816 in namespace: db_name.collection_name
在連接。 (/rc19_pricemongo/node_modules/mongodb/lib/core/connection/pool.js:466:61)
在 Connection.emit (events.js:210:5)
在 processMessage (/rc19_pricemongo/node_modules/mongodb/lib/core/connection/connection.js:364:10)
在 TLSSocket。 (/rc19_pricemongo/node_modules/mongodb/lib/core/connection/connection.js:533:15)
在 TLSSocket.emit (events.js:210:5)
在 addChunk (_stream_readable.js:309:12)
在 readableAddChunk (_stream_readable.js:290:11)
在 TLSSocket.Readable.push (_stream_readable.js:224:10)
在 TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23) {
好的:0,
errmsg: '游標未找到,游標 ID:7820213409290816 在命名空間:db_name.collection_name',代碼:43,
name: 'MongoError',
[Symbol(mongoErrorContextSymbol)]: { isGetMore: true }
我無法確定問題,任何建議都會有所幫助...
我推薦你使用find
方法,你可以傳遞一個對象作為第二個參數來接收timeout
屬性,它會阻止游標超時。
IDModel.find({},{ timeout: false })
文檔: http : //mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#find
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.