From 301a946e5848835924e40564bdf46ac60d2f75c9 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 2 Jun 2021 16:49:32 +0200 Subject: [PATCH 1/6] feat(service-provider-server): pass `promoteLongs: false` MONGOSH-809 --- packages/cli-repl/test/e2e-bson.spec.ts | 21 ++++++++++++++++++- .../src/cli-service-provider.ts | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) 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.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 }); /** From 919820dd4886245e2d4e16cd1a6c5112c6608604 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 2 Jun 2021 19:15:11 +0200 Subject: [PATCH 2/6] fixup! feat(service-provider-server): pass `promoteLongs: false` MONGOSH-809 --- packages/cli-repl/test/e2e-auth.spec.ts | 4 ++-- packages/shell-api/src/integration.spec.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli-repl/test/e2e-auth.spec.ts b/packages/cli-repl/test/e2e-auth.spec.ts index 290342fdd3..2453085c8e 100644 --- a/packages/cli-repl/test/e2e-auth.spec.ts +++ b/packages/cli-repl/test/e2e-auth.spec.ts @@ -269,7 +269,7 @@ describe('Auth e2e', function() { 'db.dropAllUsers()' ); await eventually(async() => { - shell.assertContainsOutput('{ n: 2, ok: 1 }'); + shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); }); const result = await db.command({ usersInfo: 1 }); expect(result.users.length).to.equal(0); @@ -493,7 +493,7 @@ describe('Auth e2e', function() { 'db.dropAllRoles()' ); await eventually(async() => { - shell.assertContainsOutput('{ n: 2, ok: 1 }'); + 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/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index ae00f4da71..b594b1896a 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -1781,7 +1781,7 @@ 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'); + expect(result.databases.find(db => db.name === 'admin').sizeOnDisk.constructor.name).to.equal('Long'); }); }); describe('getDBNames', () => { From 187255ee014167c4978c5909ba2481385f5feda1 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 3 Jun 2021 11:35:07 +0200 Subject: [PATCH 3/6] fixup! fixup! feat(service-provider-server): pass `promoteLongs: false` MONGOSH-809 --- .../service-provider-server/src/cli-service-provider.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From dd661ba9312c17accf7f883484f959602ccc2a8b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 3 Jun 2021 13:06:25 +0200 Subject: [PATCH 4/6] fixup! fixup! fixup! feat(service-provider-server): pass `promoteLongs: false` MONGOSH-809 --- packages/cli-repl/test/e2e-auth.spec.ts | 12 ++++++++++-- packages/shell-api/src/integration.spec.ts | 3 ++- packages/shell-api/src/mongo.ts | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/cli-repl/test/e2e-auth.spec.ts b/packages/cli-repl/test/e2e-auth.spec.ts index 2453085c8e..b709b63be6 100644 --- a/packages/cli-repl/test/e2e-auth.spec.ts +++ b/packages/cli-repl/test/e2e-auth.spec.ts @@ -269,7 +269,11 @@ describe('Auth e2e', function() { 'db.dropAllUsers()' ); await eventually(async() => { - shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); + try { + shell.assertContainsOutput('{ n: 2, ok: 1 }'); + } catch { + shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); + } }); const result = await db.command({ usersInfo: 1 }); expect(result.users.length).to.equal(0); @@ -493,7 +497,11 @@ describe('Auth e2e', function() { 'db.dropAllRoles()' ); await eventually(async() => { - shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); + try { + shell.assertContainsOutput('{ n: 2, ok: 1 }'); + } catch { + 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/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index b594b1896a..b2e8d5e944 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -1781,7 +1781,8 @@ 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.constructor.name).to.equal('Long'); + const admin = result.databases.find(db => db.name === 'admin'); + expect(typeof admin.sizeOnDisk === 'number' || admin.sizeOnDisk.constructor.name === 'Long').to.equal(true); }); }); describe('getDBNames', () => { 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'); From 9131bd6366d611da04899c4bd68bc550a313830c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 3 Jun 2021 14:36:46 +0200 Subject: [PATCH 5/6] fixup! fixup! fixup! fixup! feat(service-provider-server): pass `promoteLongs: false` MONGOSH-809 --- packages/shell-api/src/mongo.spec.ts | 1 + 1 file changed, 1 insertion(+) 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' }); }); From 161d35b536399422f19842a4d21fa75e570a8b94 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 7 Jun 2021 10:11:13 +0200 Subject: [PATCH 6/6] fixup: add comments re: version differences --- packages/cli-repl/test/e2e-auth.spec.ts | 2 ++ packages/shell-api/src/integration.spec.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/cli-repl/test/e2e-auth.spec.ts b/packages/cli-repl/test/e2e-auth.spec.ts index b709b63be6..3ade47fa37 100644 --- a/packages/cli-repl/test/e2e-auth.spec.ts +++ b/packages/cli-repl/test/e2e-auth.spec.ts @@ -272,6 +272,7 @@ describe('Auth e2e', function() { try { shell.assertContainsOutput('{ n: 2, ok: 1 }'); } catch { + // The 5.0+ server responds with a Long. shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); } }); @@ -500,6 +501,7 @@ describe('Auth e2e', function() { try { shell.assertContainsOutput('{ n: 2, ok: 1 }'); } catch { + // The 5.0+ server responds with a Long. shell.assertContainsOutput('{ n: Long("2"), ok: 1 }'); } }); diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index b2e8d5e944..3e3dbe7986 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -1782,6 +1782,7 @@ describe('Shell API (integration)', function() { const result = await mongo.getDBs(); expect(result.ok).to.equal(1); 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); }); });