Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
fix: prefer _bsontype over constructor.name in DBRef serializer (#152)
Browse files Browse the repository at this point in the history
For compatibility with BSON 4.x.
  • Loading branch information
addaleax committed Jul 6, 2021
1 parent 7b1cd35 commit 7872203
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/modes/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ module.exports.serialize = {

if (
typeof v.oid === 'object' &&
module.exports.serialize[v.oid.constructor.name]
v.oid !== null &&
(module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name])
) {
id = module.exports.serialize[v.oid.constructor.name](v.oid);
id = (module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name])(v.oid);
} else if (typeof v.oid === 'string') {
id = '"' + v.oid + '"';
} else {
Expand Down
5 changes: 3 additions & 2 deletions lib/modes/strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ module.exports = {
};
},
DBRef: function(v) {
var id = typeof v.oid === 'object'
&& module.exports.serialize[v.oid.constructor.name] ? module.exports.serialize[v.oid.constructor.name](v.oid)
var id = typeof v.oid === 'object' && v.oid !== null &&
(module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name]) ?
(module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name])(v.oid)
: v.oid;
return {
$ref: v.namespace,
Expand Down

0 comments on commit 7872203

Please sign in to comment.