-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 6.5.0
-
Component/s: BSON, Server Selection
Code:
```
const client = new mongo.MongoClient(uri, { });
const db = client.db('test',
);
```
Error:
```
TypeError: Cannot convert a BigInt value to a number
?, in isNaN
File "/app/node_modules/.pnpm/bson@6.6.0/node_modules/bson/lib/bson.cjs", line 908, col 13, in Long.fromNumber
if (isNaN(value))
File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server_description.js", line 185, col 88, in compareTopologyVersion
const newCounter = bson_1.Long.isLong(newTv.counter) ? newTv.counter : bson_1.Long.fromNumber(newTv.counter);
File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 356, col 60, in shouldHandleStateChangeError
return (0, server_description_1.compareTopologyVersion)(stv, etv) < 0;
File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 225, col 21, in Server.handleError
if (shouldHandleStateChangeError(this, error)) {
File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 287, col 14, in Server.decorateCommandError
this.handleError(error, connection);
File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/sdam/server.js", line 172, col 28, in Server.command
throw this.decorateCommandError(conn, cmd, finalOptions, commandError);
File "node:internal/process/task_queues", line 95, col 5, in process.processTicksAndRejections
File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/operations/find_and_modify.js", line 91, col 24, in FindOneAndUpdateOperation.execute
const result = await super.executeCommand(server, session, cmd);
File "/app/node_modules/.pnpm/mongodb@6.5.0/node_modules/mongodb/lib/operations/execute_operation.js", line 126, col 16, in executeOperation
return await operation.execute(server, session);
```
I'm not sure what exactly triggers this. It happens often in production, but from reading the stack trace, it's only if something else triggered some kind of error on the connection.
The core issue appears to be that the code assumes the counter is either a number or Long, but useBigInt64 causes it to be a bigint instead.
- related to
-
NODE-2674 On Demand BSON Access
- Development Complete