diff --git a/packages/java-shell/src/main/js/all.js b/packages/java-shell/src/main/js/all.js index 9a3bb50095..242e2da72a 100644 --- a/packages/java-shell/src/main/js/all.js +++ b/packages/java-shell/src/main/js/all.js @@ -24,9 +24,15 @@ require('../../../../service-provider-core'); // Ensure TextEncoder polyfill is const ShellApi = require('../../../../shell-api/'); const ShellEvaluator = require('../../../../shell-evaluator/').default; +class ShellInstanceState extends ShellApi.ShellInstanceState { + constructor(sp, bus, cliOptions) { + super(sp, bus, cliOptions, require('bson')); + } +} + /** temporal object that is used to access symbols from closures generated by browserify */ _global = { - ShellInstanceState: ShellApi.ShellInstanceState, + ShellInstanceState, ShellEvaluator: ShellEvaluator, toShellResult: ShellApi.toShellResult, getShellApiType: ShellApi.getShellApiType, diff --git a/packages/java-shell/src/test/js/run-tests.ts b/packages/java-shell/src/test/js/run-tests.ts index f4e14bd14a..ccbfa02a03 100644 --- a/packages/java-shell/src/test/js/run-tests.ts +++ b/packages/java-shell/src/test/js/run-tests.ts @@ -33,6 +33,9 @@ describe('java-shell tests', function() { proc = spawn('.\\gradlew.bat test --info', [], opts); } await once(proc, 'exit'); + if (proc.exitCode !== 0) { + throw new Error(`java-shell tests failed (exit code ${proc.exitCode}, signal ${proc.signalCode})`); + } }); }); diff --git a/packages/java-shell/src/test/resources/collection/aggregateWithNegativeBatchSize.expected.4.txt b/packages/java-shell/src/test/resources/collection/aggregateWithNegativeBatchSize.expected.4.txt new file mode 100644 index 0000000000..89c534fae5 --- /dev/null +++ b/packages/java-shell/src/test/resources/collection/aggregateWithNegativeBatchSize.expected.4.txt @@ -0,0 +1 @@ +com.mongodb.MongoCommandException: Command failed with error 2 (BadValue): 'BSON field 'batchSize' value must be >= 0, actual value '-1'' on server %mongohostport%. The full response is {"ok": 0.0, "errmsg": "BSON field 'batchSize' value must be >= 0, actual value '-1'", "code": 2, "codeName": "BadValue"} diff --git a/packages/java-shell/src/test/resources/db/help.expected.txt b/packages/java-shell/src/test/resources/db/help.expected.txt index fe42d8bdfe..7958090eeb 100644 --- a/packages/java-shell/src/test/resources/db/help.expected.txt +++ b/packages/java-shell/src/test/resources/db/help.expected.txt @@ -1,4 +1,4 @@ ArrayResult ArrayResult -"use" -"use" \ No newline at end of file +"log" +"log" diff --git a/packages/java-shell/src/test/resources/literal/ISODate.js b/packages/java-shell/src/test/resources/literal/ISODate.js index 2a60a1b379..4d57f58ec0 100644 --- a/packages/java-shell/src/test/resources/literal/ISODate.js +++ b/packages/java-shell/src/test/resources/literal/ISODate.js @@ -31,4 +31,4 @@ ISODate('2012-12-19T140505') // command checkResultClass db.coll.find().toArray()[0].v; // clear -db.coll.drop(); \ No newline at end of file +db.coll.drop(); diff --git a/packages/java-shell/src/test/resources/literal/long.expected.1.txt b/packages/java-shell/src/test/resources/literal/long.expected.1.txt new file mode 100644 index 0000000000..417ccd87b2 --- /dev/null +++ b/packages/java-shell/src/test/resources/literal/long.expected.1.txt @@ -0,0 +1,3 @@ +LongResult: 2147483649 +DoubleResult: 1281104301025214500 +LongResult: 1281104301025214467 diff --git a/packages/shell-api/src/collection.ts b/packages/shell-api/src/collection.ts index dc574843f5..3836231685 100644 --- a/packages/shell-api/src/collection.ts +++ b/packages/shell-api/src/collection.ts @@ -525,7 +525,12 @@ export class Collection< CommonErrors.InvalidArgument ); } - reducedOptions.projection ??= reducedOptions.fields; + if ( + reducedOptions.projection === undefined && + reducedOptions.fields !== undefined + ) { + reducedOptions.projection ??= reducedOptions.fields; + } delete (reducedOptions as any).query; delete (reducedOptions as any).update; delete (reducedOptions as any).fields; diff --git a/packages/shell-api/src/shell-instance-state.ts b/packages/shell-api/src/shell-instance-state.ts index 22f65c160d..f2f402f4a1 100644 --- a/packages/shell-api/src/shell-instance-state.ts +++ b/packages/shell-api/src/shell-instance-state.ts @@ -39,7 +39,11 @@ import { import { InterruptFlag } from './interruptor'; import { TransformMongoErrorPlugin } from './mongo-errors'; import NoDatabase from './no-db'; -import { type ShellBson, constructShellBson } from '@mongosh/shell-bson'; +import { + type ShellBson, + constructShellBson, + type BSON as BSONLibrary, +} from '@mongosh/shell-bson'; import { Streams } from './streams'; import { ShellLog } from './shell-log'; @@ -158,6 +162,7 @@ export class ShellInstanceState { public currentDb: DatabaseWithSchema; public messageBus: MongoshBus; public initialServiceProvider: ServiceProvider; // the initial service provider + private bsonLibrary: BSONLibrary; private connectionInfoCache: { // Caching/lazy-loading functionality for the ServiceProvider's getConnectionInfo() // return value. We store the ServiceProvider instance for which we are @@ -195,9 +200,11 @@ export class ShellInstanceState { constructor( initialServiceProvider: ServiceProvider, messageBus: any = new EventEmitter(), - cliOptions: ShellCliOptions = {} + cliOptions: ShellCliOptions = {}, + bsonLibrary: BSONLibrary = initialServiceProvider.bsonLibrary ) { this.initialServiceProvider = initialServiceProvider; + this.bsonLibrary = bsonLibrary; this.messageBus = messageBus; this.shellApi = new ShellApi(this); this.shellLog = new ShellLog(this); @@ -230,7 +237,7 @@ export class ShellInstanceState { private constructShellBson(): ShellBson { return constructShellBson({ - bsonLibrary: this.initialServiceProvider.bsonLibrary, + bsonLibrary: this.bsonLibrary, printWarning: (msg: string) => { void this.shellApi.print(`Warning: ${msg}`); },