-
Type: Question
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
I have tested the node.js mongodb driver 4.x, 5.x, 6.x and found some interesting results.
When using commonjs, all versions have the same behavior. the class (e.g. Decimal128) imported from "mongodb" and "bson" are the same instance.
When using es module, version 4.x has the same behavior as commonjs, but 5.x and 6.x have different behavior. The class imported from "mongodb" and "bson" are different instances.
I'm curious that is it intended?
I'v tested it in node-20.10.0 and no packages installed other than the mognodb. So I'm pretty sure that there is only one version of bson package installed.
// for es module (set "type": "module" in package.json)
import assert from 'assert'
import { Decimal128 as D1 } from 'mongodb'
import { Decimal128 as D2 } from 'bson'
// for commonjs
const assert = require('assert')
const { Decimal128: D1 } = require('mongodb')
const { Decimal128: D2 } = require('bson')
// commonjs: passed for 4.x, 5.x and 6.x
// esmodule: passed for 4.x, failed for 5.x and 6.x
assert(D1.fromString('1.234') instanceof D2)