From 67a93c6d85bd6c005713d852959e64113f806329 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 12 Feb 2021 17:38:30 +0100 Subject: [PATCH 1/3] fix(service-provider-server): accept functions in createView MONGOSH-585 --- .../src/cli-service-provider.ts | 1 + packages/shell-api/src/integration.spec.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/service-provider-server/src/cli-service-provider.ts b/packages/service-provider-server/src/cli-service-provider.ts index 586e644d23..38d12305e7 100644 --- a/packages/service-provider-server/src/cli-service-provider.ts +++ b/packages/service-provider-server/src/cli-service-provider.ts @@ -1085,6 +1085,7 @@ class CliServiceProvider extends ServiceProviderCore implements ServiceProvider options: CreateCollectionOptions = {}, dbOptions?: DbOptions ): Promise<{ ok: number }> { + options = { ...this.baseCmdOptions, ...options }; await this.db(dbName, dbOptions).createCollection( collName, options ); diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index a9def77aae..42db515411 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -983,6 +983,31 @@ describe('Shell API (integration)', function() { } ]); }); + it('creates a view that potentially contains JS functions in its pipeline', async() => { + const pipeline = (body: any) => [{ + '$set': { + 'name_md5': { '$function': { 'lang': 'js', 'args': ['$name'], 'body': body } } + } + }]; + const fn = compileExpr `function (val) { + return hex_md5(val); + }`; + expect( + await database.createView( + 'view', + 'source', + pipeline(fn) + ) + ).to.deep.equal({ ok: 1 }); + const views = await serviceProvider.find(dbName, 'system.views', {}).toArray(); + expect(JSON.parse(JSON.stringify(views))).to.deep.equal([ + { + _id: `${dbName}.view`, + viewOn: 'source', + pipeline: pipeline({ code: fn.toString() }) + } + ]); + }); }); }); From 61877ed55758fa56efbefb24a2306d0d13b838d6 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 12 Feb 2021 18:59:53 +0100 Subject: [PATCH 2/3] fixup! fix(service-provider-server): accept functions in createView MONGOSH-585 --- .../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 3a48acc6a2..18f00d96bb 100644 --- a/packages/service-provider-server/src/cli-service-provider.spec.ts +++ b/packages/service-provider-server/src/cli-service-provider.spec.ts @@ -726,7 +726,7 @@ describe('CliServiceProvider', () => { it('executes the command', async() => { const result = await serviceProvider.createCollection('db1', 'newcoll', {}); expect(result).to.deep.equal({ ok: 1 }); - expect(dbStub.createCollection).to.have.been.calledOnceWith('newcoll', {}); + expect(dbStub.createCollection).to.have.been.calledOnceWith('newcoll', DEFAULT_BASE_OPTS); expect(clientStub.db).to.have.been.calledOnceWith('db1'); }); }); From 87312280d0fce419c16af231159b477d665b090a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 15 Feb 2021 10:57:50 +0100 Subject: [PATCH 3/3] fixup! fixup! fix(service-provider-server): accept functions in createView MONGOSH-585 --- packages/shell-api/src/integration.spec.ts | 51 ++++++++++++---------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/packages/shell-api/src/integration.spec.ts b/packages/shell-api/src/integration.spec.ts index 42db515411..e7ec5ecd18 100644 --- a/packages/shell-api/src/integration.spec.ts +++ b/packages/shell-api/src/integration.spec.ts @@ -983,30 +983,33 @@ describe('Shell API (integration)', function() { } ]); }); - it('creates a view that potentially contains JS functions in its pipeline', async() => { - const pipeline = (body: any) => [{ - '$set': { - 'name_md5': { '$function': { 'lang': 'js', 'args': ['$name'], 'body': body } } - } - }]; - const fn = compileExpr `function (val) { - return hex_md5(val); - }`; - expect( - await database.createView( - 'view', - 'source', - pipeline(fn) - ) - ).to.deep.equal({ ok: 1 }); - const views = await serviceProvider.find(dbName, 'system.views', {}).toArray(); - expect(JSON.parse(JSON.stringify(views))).to.deep.equal([ - { - _id: `${dbName}.view`, - viewOn: 'source', - pipeline: pipeline({ code: fn.toString() }) - } - ]); + context('features only available on mongodb 4.4+', () => { + skipIfServerVersion(testServer, '< 4.4'); + it('creates a view that potentially contains JS functions in its pipeline', async() => { + const pipeline = (body: any) => [{ + '$set': { + 'name_md5': { '$function': { 'lang': 'js', 'args': ['$name'], 'body': body } } + } + }]; + const fn = compileExpr `function (val) { + return hex_md5(val); + }`; + expect( + await database.createView( + 'view', + 'source', + pipeline(fn) + ) + ).to.deep.equal({ ok: 1 }); + const views = await serviceProvider.find(dbName, 'system.views', {}).toArray(); + expect(JSON.parse(JSON.stringify(views))).to.deep.equal([ + { + _id: `${dbName}.view`, + viewOn: 'source', + pipeline: pipeline({ code: fn.toString() }) + } + ]); + }); }); }); });