diff --git a/packages/cli-repl/test/e2e-auth.spec.ts b/packages/cli-repl/test/e2e-auth.spec.ts index 290342fdd3..3ade47fa37 100644 --- a/packages/cli-repl/test/e2e-auth.spec.ts +++ b/packages/cli-repl/test/e2e-auth.spec.ts @@ -269,7 +269,12 @@ describe('Auth e2e', function() { 'db.dropAllUsers()' ); await eventually(async() => { - shell.assertContainsOutput('{ n: 2, ok: 1 }'); + try { + shell.assertContainsOutput('{ n: 2, ok: 1 }'); + } catch { + // The 5.0+ server responds with a Long. + shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); + } }); const result = await db.command({ usersInfo: 1 }); expect(result.users.length).to.equal(0); @@ -493,7 +498,12 @@ describe('Auth e2e', function() { 'db.dropAllRoles()' ); await eventually(async() => { - shell.assertContainsOutput('{ n: 2, ok: 1 }'); + try { + shell.assertContainsOutput('{ n: 2, ok: 1 }'); + } catch { + // The 5.0+ server responds with a Long. + shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); + } }); const result = await db.command({ rolesInfo: 1 }); expect(result.roles.length).to.equal(0); diff --git a/packages/cli-repl/test/e2e-bson.spec.ts b/packages/cli-repl/test/e2e-bson.spec.ts index d9e59da932..6f24af0a9c 100644 --- a/packages/cli-repl/test/e2e-bson.spec.ts +++ b/packages/cli-repl/test/e2e-bson.spec.ts @@ -156,6 +156,26 @@ describe('BSON e2e', function() { }); shell.assertNoErrors(); }); + it('NumberLong prints when returned from the server', async() => { + const value = new bson.Long('64'); + await shell.writeInputLine(`use ${dbName}`); + await db.collection('test').insertOne({ value: value }); + await shell.writeInputLine('db.test.findOne().value'); + await eventually(() => { + shell.assertContainsOutput('Long("64")'); + }); + shell.assertNoErrors(); + }); + it('NumberLong prints when returned from the server (> MAX_SAFE_INTEGER)', async() => { + const value = new bson.Long('345678654321234561'); + await shell.writeInputLine(`use ${dbName}`); + await db.collection('test').insertOne({ value: value }); + await shell.writeInputLine('db.test.findOne().value'); + await eventually(() => { + shell.assertContainsOutput('Long("345678654321234561")'); + }); + shell.assertNoErrors(); + }); it('Timestamp prints when returned from the server', async() => { const value = new bson.Timestamp(0, 100); await shell.writeInputLine(`use ${dbName}`); @@ -365,7 +385,6 @@ describe('BSON e2e', function() { }); }); describe('help methods', () => { - // NOTE: the driver returns regular JS objects for Int32, Long it('ObjectId has help when returned from the server', async() => { const value = new bson.ObjectId(); await shell.writeInputLine(`use ${dbName}`); diff --git a/packages/service-provider-server/src/cli-service-provider.spec.ts b/packages/service-provider-server/src/cli-service-provider.spec.ts index 66b3383f0d..7c2a5def9a 100644 --- a/packages/service-provider-server/src/cli-service-provider.spec.ts +++ b/packages/service-provider-server/src/cli-service-provider.spec.ts @@ -10,7 +10,7 @@ import { EventEmitter } from 'events'; chai.use(sinonChai); -const DEFAULT_BASE_OPTS = { serializeFunctions: true }; +const DEFAULT_BASE_OPTS = { serializeFunctions: true, promoteLongs: false }; /** * Create a client stub from the provided collection stub. diff --git a/packages/service-provider-server/src/cli-service-provider.ts b/packages/service-provider-server/src/cli-service-provider.ts index 5fa80ff12b..966c16137d 100644 --- a/packages/service-provider-server/src/cli-service-provider.ts +++ b/packages/service-provider-server/src/cli-service-provider.ts @@ -132,7 +132,8 @@ function processDriverOptions(opts: MongoClientOptions): MongoClientOptions { * Default driver method options we always use. */ const DEFAULT_BASE_OPTIONS: OperationOptions = Object.freeze({ - serializeFunctions: true + serializeFunctions: true, + promoteLongs: false }); /** diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index ae00f4da71..3e3dbe7986 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -1781,7 +1781,9 @@ describe('Shell API (integration)', function() { it('lists all databases', async() => { const result = await mongo.getDBs(); expect(result.ok).to.equal(1); - expect(result.databases.find(db => db.name === 'admin').sizeOnDisk).to.be.a('number'); + const admin = result.databases.find(db => db.name === 'admin'); + // The 5.0+ server responds with a Long. + expect(typeof admin.sizeOnDisk === 'number' || admin.sizeOnDisk.constructor.name === 'Long').to.equal(true); }); }); describe('getDBNames', () => { diff --git a/packages/shell-api/src/mongo.spec.ts b/packages/shell-api/src/mongo.spec.ts index a3e25e0cdc..302fd46263 100644 --- a/packages/shell-api/src/mongo.spec.ts +++ b/packages/shell-api/src/mongo.spec.ts @@ -124,6 +124,7 @@ describe('Mongo', () => { database._getCollectionNamesWithTypes.resolves(expectedResult); await mongo.show(t); expect(database._getCollectionNamesWithTypes).to.have.been.calledWith({ + promoteLongs: true, readPreference: 'primaryPreferred' }); }); diff --git a/packages/shell-api/src/mongo.ts b/packages/shell-api/src/mongo.ts index ba54c01263..a35f7b30a8 100644 --- a/packages/shell-api/src/mongo.ts +++ b/packages/shell-api/src/mongo.ts @@ -273,11 +273,11 @@ export default class Mongo extends ShellApiClass { switch (cmd) { case 'databases': case 'dbs': - const result = (await this._listDatabases({ readPreference: 'primaryPreferred' })).databases; + const result = (await this._listDatabases({ readPreference: 'primaryPreferred', promoteLongs: true })).databases; return new CommandResult('ShowDatabasesResult', result); case 'collections': case 'tables': - const collectionNames = await this._internalState.currentDb._getCollectionNamesWithTypes({ readPreference: 'primaryPreferred' }); + const collectionNames = await this._internalState.currentDb._getCollectionNamesWithTypes({ readPreference: 'primaryPreferred', promoteLongs: true }); return new CommandResult('ShowCollectionsResult', collectionNames); case 'profile': const sysprof = this._internalState.currentDb.getCollection('system.profile');