Skip to content

Commit 8b5a2b1

Browse files
authored
fix(service-provider-server): accept functions in createView MONGOSH-585 (#655)
1 parent 62c3d11 commit 8b5a2b1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

packages/service-provider-server/src/cli-service-provider.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ describe('CliServiceProvider', () => {
726726
it('executes the command', async() => {
727727
const result = await serviceProvider.createCollection('db1', 'newcoll', {});
728728
expect(result).to.deep.equal({ ok: 1 });
729-
expect(dbStub.createCollection).to.have.been.calledOnceWith('newcoll', {});
729+
expect(dbStub.createCollection).to.have.been.calledOnceWith('newcoll', DEFAULT_BASE_OPTS);
730730
expect(clientStub.db).to.have.been.calledOnceWith('db1');
731731
});
732732
});

packages/service-provider-server/src/cli-service-provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ class CliServiceProvider extends ServiceProviderCore implements ServiceProvider
10851085
options: CreateCollectionOptions = {},
10861086
dbOptions?: DbOptions
10871087
): Promise<{ ok: number }> {
1088+
options = { ...this.baseCmdOptions, ...options };
10881089
await this.db(dbName, dbOptions).createCollection(
10891090
collName, options
10901091
);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,34 @@ describe('Shell API (integration)', function() {
983983
}
984984
]);
985985
});
986+
context('features only available on mongodb 4.4+', () => {
987+
skipIfServerVersion(testServer, '< 4.4');
988+
it('creates a view that potentially contains JS functions in its pipeline', async() => {
989+
const pipeline = (body: any) => [{
990+
'$set': {
991+
'name_md5': { '$function': { 'lang': 'js', 'args': ['$name'], 'body': body } }
992+
}
993+
}];
994+
const fn = compileExpr `function (val) {
995+
return hex_md5(val);
996+
}`;
997+
expect(
998+
await database.createView(
999+
'view',
1000+
'source',
1001+
pipeline(fn)
1002+
)
1003+
).to.deep.equal({ ok: 1 });
1004+
const views = await serviceProvider.find(dbName, 'system.views', {}).toArray();
1005+
expect(JSON.parse(JSON.stringify(views))).to.deep.equal([
1006+
{
1007+
_id: `${dbName}.view`,
1008+
viewOn: 'source',
1009+
pipeline: pipeline({ code: fn.toString() })
1010+
}
1011+
]);
1012+
});
1013+
});
9861014
});
9871015
});
9881016

0 commit comments

Comments
 (0)