Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/cli-repl/test/e2e-auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 20 additions & 1 deletion packages/cli-repl/test/e2e-bson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/shell-api/src/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/shell-api/src/mongo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/shell-api/src/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down