Skip to content

Commit 267325a

Browse files
authored
fix(shell-api): totalSize handles Long values from stats MONGOSH-1126 (#1215)
1 parent 62b1dff commit 267325a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

packages/shell-api/src/collection.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,17 +1202,18 @@ describe('Collection', () => {
12021202
});
12031203

12041204
describe('totalSize', () => {
1205-
let result;
1206-
1207-
beforeEach(() => {
1208-
result = { storageSize: 1000, totalIndexSize: 1000 };
1209-
serviceProvider.stats.resolves(result);
1210-
});
1211-
12121205
it('returns sum of storageSize and totalIndexSize', async() => {
1206+
const result = { storageSize: 1000, totalIndexSize: 1000 };
1207+
serviceProvider.stats.resolves(result);
12131208
expect(await collection.totalSize()).to.equal(2000);
12141209
expect(serviceProvider.stats).to.have.been.calledOnceWith('db1', 'coll1');
12151210
});
1211+
it('should handle Long numbers correctly', async() => {
1212+
const result = { storageSize: bson.Long.fromNumber(1732749910016), totalIndexSize: 10559533056 };
1213+
serviceProvider.stats.resolves(result);
1214+
expect(await collection.totalSize()).to.equal(1743309443072);
1215+
expect(serviceProvider.stats).to.have.been.calledOnceWith('db1', 'coll1');
1216+
});
12161217
});
12171218

12181219
describe('drop', () => {

packages/shell-api/src/collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ export default class Collection extends ShellApiWithMongoClass {
13061306
async totalSize(): Promise<number> {
13071307
this._emitCollectionApiCall('totalSize');
13081308
const stats = await this._mongo._serviceProvider.stats(this._database._name, this._name, await this._database._baseOptions());
1309-
return (stats.storageSize || 0) + (stats.totalIndexSize || 0);
1309+
return (Number(stats.storageSize) || 0) + (Number(stats.totalIndexSize) || 0);
13101310
}
13111311

13121312
/**

0 commit comments

Comments
 (0)