diff --git a/src/parser/calculate_size.ts b/src/parser/calculate_size.ts index 923beeb0..da62ae6c 100644 --- a/src/parser/calculate_size.ts +++ b/src/parser/calculate_size.ts @@ -205,6 +205,9 @@ function calculateElement( 1 ); } + return 0; + case 'bigint': + return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1); } return 0; diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index 3ebccd16..e421c28f 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -24,4 +24,10 @@ describe('calculateSize()', () => { }) ).to.throw(BSONVersionError, /Unsupported BSON version/i); }); + + it('returns the correct size for a bigint value', function () { + const doc = { a: BigInt(1) }; + expect(BSON.calculateObjectSize(doc)).to.equal(16); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); });