Skip to content
Open
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
8 changes: 7 additions & 1 deletion packages/java-shell/src/main/js/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/java-shell/src/test/js/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`);
}
});
});

Original file line number Diff line number Diff line change
@@ -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"}
4 changes: 2 additions & 2 deletions packages/java-shell/src/test/resources/db/help.expected.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ArrayResult
ArrayResult
"use"
"use"
"log"
"log"
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ ISODate('2012-12-19T140505')
// command checkResultClass
db.coll.find().toArray()[0].v;
// clear
db.coll.drop();
db.coll.drop();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LongResult: 2147483649
DoubleResult: 1281104301025214500
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ Apparently it depends on some external factor (Java version?) whether evaluating 1281104301025214467 as a JS string results in 1281104301025214460 or 1281104301025214500 when stringified again. Since the latter seems to be the JS standard behavior, I think it's okay to add this as an alternative here

LongResult: 1281104301025214467
7 changes: 6 additions & 1 deletion packages/shell-api/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions packages/shell-api/src/shell-instance-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);
},
Expand Down