[BUG.v5.2.1] ClientSession cannot be serialized to BSON - Sessions
See original GitHub issueHello; trying to use simple transaction case as described in the documentation; I’m getting an error
ClientSession cannot be serialized to BSON.
at ClientSession.toBSON (/eliot-local-git/node_modules/mongoose/node_modules/mongodb-core/lib/sessions.js:225:11)
at serializeInto (/eliot-local-git/node_modules/bson/lib/bson/parser/serializer.js:895:23)
at serializeObject (/eliot-local-git/node_modules/bson/lib/bson/parser/serializer.js:347:18)
at serializeInto (/eliot-local-git/node_modules/bson/lib/bson/parser/serializer.js:937:17)
at BSON.serialize (/eliot-local-git/node_modules/bson/lib/bson/bson.js:63:28)
at Query.toBin (/eliot-local-git/node_modules/mongoose/node_modules/mongodb-core/lib/connection/commands.js:144:25)
at serializeCommands (/eliot-local-git/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:1044:43)
at Pool.write (/eliot-local-git/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:1260:3)
at Cursor._find (/eliot-local-git/node_modules/mongoose/node_modules/mongodb-core/lib/cursor.js:326:22)
at nextFunction (/eliot-local-git/node_modules/mongoose/node_modules/mongodb-core/lib/cursor.js:673:10)
at Cursor.next (/eliot-local-git/node_modules/mongoose/node_modules/mongodb-core/lib/cursor.js:824:3)
at Cursor._next (/eliot-local-git/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:211:36)
at nextObject (/eliot-local-git/node_modules/mongoose/node_modules/mongodb/lib/operations/cursor_ops.js:186:10)
at next (/eliot-local-git/node_modules/mongoose/node_modules/mongodb/lib/operations/cursor_ops.js:165:3)
at executeOperation (/eliot-local-git/node_modules/mongoose/node_modules/mongodb/lib/utils.js:420:24)
at Cursor.next (/eliot-local-git/node_modules/mongoose/node_modules/mongodb/lib/cursor.js:253:10)
My code look like :
const session = await model.startSession();
const oneCompany = await model.findOne({}, {
projection: '_id',
session,
});
const oneLanguage = await classes.Language.schema.getModel().findOneAndUpdate({
_id: 'aaaaa0000000000000000000',
}, {
'name.description': 'lelz',
}, {
new: true,
projection: '_id',
session,
});
await session.commitTransaction();
session.endSession();
Versions I use :
node.js v9.11.1 mongoose@5.2.1 mongodb@3.1.0 (mongo native node driver) mongodb-core@3.1.0 (mongo native node driver) mongodb v4.0.0 (database)
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
ClientSession cannot be serialized to BSON - Mongodb ...
turns out I have to pass session on the 3rd parameter on find method and wrap payload as an array on create method...
Read more >mongodb - UNPKG
180, export declare interface AbstractCursorOptions extends BSONSerializeOptions {. 181, session?: ClientSession;. 182, readPreference?: ReadPreferenceLike;.
Read more >mongoose | Yarn - Package Manager
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports Node.js and Deno (alpha). Build Status NPM...
Read more >Spring Data MongoDB - Reference Documentation
Improved support for <mongo:mongo-client credentials="…" /> . Improved index creation failure error message. 6.11. What's New in Spring Data ...
Read more >A MongoDB Collection - metacpan.org
Cannot be specified together with resumeAfter . Plain values will be coerced to BSON::Timestamp objects. session - the session to use for these...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is a common gotcha that we should add docs for, but your issue is that the 2nd arg to
Model.findOne()is always a projection. You need to doawait A.findOne({}, null, { session });@vkarpov15 your example worked