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
12 changes: 12 additions & 0 deletions packages/shell-api/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { AutoEncryptionOptions } from 'mongodb';
import { shellApiType } from './enums';
import type { AbstractCursor } from './abstract-cursor';
import type ChangeStreamCursor from './change-stream-cursor';
import { inspect } from 'util';

/**
* Helper method to adapt aggregation pipeline options.
Expand Down Expand Up @@ -458,6 +459,17 @@ export async function getPrintableShardStatus(db: Database, verbose: boolean): P
'on shard': chunk.shard,
'last modified': chunk.lastmod
} as any;
// Displaying a full, multi-line output for each chunk is a bit verbose,
// even if there are only a few chunks. Where supported, we use a custom
// inspection function to inspect a copy of this object with an unlimited
// line break length (i.e. all objects on a single line).
Object.defineProperty(c, Symbol.for('nodejs.util.inspect.custom'), {
value: function(depth: number, options: any): string {
return inspect({ ...this }, { ...options, breakLength: Infinity });
},
writable: true,
configurable: true
});
if (chunk.jumbo) c.jumbo = 'yes';
chunksRes.push(c);
});
Expand Down
19 changes: 13 additions & 6 deletions packages/shell-api/src/shard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { UpdateResult } from './result';
import { CliServiceProvider } from '../../service-provider-server';
import { startTestCluster, skipIfServerVersion, skipIfApiStrict } from '../../../testing/integration-testing-hooks';
import Database from './database';
import { ObjectId } from 'mongodb';
import { inspect } from 'util';

describe('Shard', () => {
skipIfApiStrict();
Expand Down Expand Up @@ -685,7 +685,7 @@ describe('Shard', () => {

it('returns whatever serviceProvider.updateOne returns', async() => {
serviceProvider.runCommandWithCheck.resolves({ ok: 1, msg: 'isdbgrid' });
const oid = new ObjectId();
const oid = new bson.ObjectId();
const expectedResult = {
matchedCount: 1,
modifiedCount: 1,
Expand Down Expand Up @@ -744,7 +744,7 @@ describe('Shard', () => {

it('returns whatever serviceProvider.updateOne returns', async() => {
serviceProvider.runCommandWithCheck.resolves({ ok: 1, msg: 'isdbgrid' });
const oid = new ObjectId();
const oid = new bson.ObjectId();
const expectedResult = {
matchedCount: 1,
modifiedCount: 1,
Expand Down Expand Up @@ -919,7 +919,7 @@ describe('Shard', () => {

it('returns whatever serviceProvider.updateOne returns', async() => {
serviceProvider.runCommandWithCheck.resolves({ ok: 1, msg: 'isdbgrid' });
const oid = new ObjectId();
const oid = new bson.ObjectId();
const expectedResult = {
matchedCount: 1,
modifiedCount: 1,
Expand Down Expand Up @@ -977,7 +977,7 @@ describe('Shard', () => {

it('returns whatever serviceProvider.updateOne returns', async() => {
serviceProvider.runCommandWithCheck.resolves({ ok: 1, msg: 'isdbgrid' });
const oid = new ObjectId();
const oid = new bson.ObjectId();
const expectedResult = {
matchedCount: 1,
modifiedCount: 1,
Expand Down Expand Up @@ -1285,7 +1285,14 @@ describe('Shard', () => {
expect(original.key).to.equal('A');
expect(original.value).to.equal(10);

expect((await sh.status()).value.databases[1].collections[ns].chunkMetadata).to.have.lengthOf(1);
const collectionInfo = (await sh.status()).value.databases[1].collections[ns];
expect(collectionInfo.chunkMetadata).to.have.lengthOf(1);
const inspectedCollectionInfo = inspect(collectionInfo);
// Make sure that each individual chunk in the output is on a single line
expect(inspectedCollectionInfo).to.include('chunks: [\n' +
' { min: { key: MinKey() }, max: { key: MaxKey() }, ' +
`'on shard': '${collectionInfo.chunks[0]['on shard']}', 'last modified': Timestamp(0, 1) }\n` +
' ],\n');
});
});
describe('autosplit', () => {
Expand Down