我的 mongodb 是 3.6,我的 nodejs 应用程序使用的是 mongo 客户端 3.0。下面是使用 mongo 客户端会话来确保因果关系的源代码:
const session = client.startSession();
const col = client.db('test').collection('test');
col
.insert({a: true}, {w: 0, j: false, session})
.then(() => {
return col.count({session});
})
.then(ret => {
console.log(ret);
}).catch(err => console.error(err));
session.endSession();
}
Run Code Online (Sandbox Code Playgroud)
运行此应用程序时出现以下错误。它无需为insertorcount命令指定会话即可工作。我想知道在这种情况下如何使用 session。
{ MongoError: Use of expired sessions is not permitted
at executeOperation (/Users/joey/dev/mongodb/demo/node_modules/mongodb/lib/utils.js:390:13)
at Collection.count (/Users/joey/dev/mongodb/demo/node_modules/mongodb/lib/collection.js:1889:10)
at col.insert.then (/Users/joey/dev/mongodb/demo/index.js:33:18)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
name: 'MongoError',
message: 'Use of expired sessions is not permitted' }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3134 次 |
| 最近记录: |