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

Commit 7872203

Browse files
authoredJul 6, 2021
fix: prefer _bsontype over constructor.name in DBRef serializer (#152)
For compatibility with BSON 4.x.
1 parent 7b1cd35 commit 7872203

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed
 

‎lib/modes/shell.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ module.exports.serialize = {
111111

112112
if (
113113
typeof v.oid === 'object' &&
114-
module.exports.serialize[v.oid.constructor.name]
114+
v.oid !== null &&
115+
(module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name])
115116
) {
116-
id = module.exports.serialize[v.oid.constructor.name](v.oid);
117+
id = (module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name])(v.oid);
117118
} else if (typeof v.oid === 'string') {
118119
id = '"' + v.oid + '"';
119120
} else {

‎lib/modes/strict.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ module.exports = {
3030
};
3131
},
3232
DBRef: function(v) {
33-
var id = typeof v.oid === 'object'
34-
&& module.exports.serialize[v.oid.constructor.name] ? module.exports.serialize[v.oid.constructor.name](v.oid)
33+
var id = typeof v.oid === 'object' && v.oid !== null &&
34+
(module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name]) ?
35+
(module.exports.serialize[v.oid._bsontype] || module.exports.serialize[v.oid.constructor.name])(v.oid)
3536
: v.oid;
3637
return {
3738
$ref: v.namespace,

0 commit comments

Comments
 (0)
This repository has been archived.