Skip to content

Commit f713902

Browse files
authored
fix(query-bar): use hint in query COMPASS-9373 (#7581)
1 parent f6f6c48 commit f713902

File tree

21 files changed

+166
-550
lines changed

21 files changed

+166
-550
lines changed

package-lock.json

Lines changed: 103 additions & 509 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-aggregations/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"@mongodb-js/explain-plan-helper": "^1.4.24",
7676
"@mongodb-js/mongodb-constants": "^0.17.0",
7777
"@mongodb-js/my-queries-storage": "^0.50.1",
78-
"@mongodb-js/shell-bson-parser": "^1.2.0",
78+
"@mongodb-js/shell-bson-parser": "^1.3.3",
7979
"bson": "^6.10.4",
8080
"compass-preferences-model": "^2.66.2",
8181
"hadron-document": "^8.10.5",
@@ -87,7 +87,7 @@
8787
"mongodb-database-model": "^2.36.0",
8888
"mongodb-instance-model": "^12.58.2",
8989
"mongodb-ns": "^3.0.1",
90-
"mongodb-query-parser": "^4.3.0",
90+
"mongodb-query-parser": "^4.5.0",
9191
"mongodb-schema": "^12.6.3",
9292
"re-resizable": "^6.9.0",
9393
"react": "^17.0.2",

packages/compass-crud/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"@mongodb-js/explain-plan-helper": "^1.4.24",
8686
"@mongodb-js/my-queries-storage": "^0.50.1",
8787
"@mongodb-js/reflux-state-mixin": "^1.2.24",
88-
"@mongodb-js/shell-bson-parser": "^1.2.0",
88+
"@mongodb-js/shell-bson-parser": "^1.3.3",
8989
"ag-grid-community": "^20.2.0",
9090
"ag-grid-react": "^20.2.0",
9191
"bson": "^6.10.4",
@@ -97,7 +97,7 @@
9797
"mongodb": "^6.19.0",
9898
"mongodb-data-service": "^22.35.0",
9999
"mongodb-ns": "^3.0.1",
100-
"mongodb-query-parser": "^4.3.0",
100+
"mongodb-query-parser": "^4.5.0",
101101
"react": "^17.0.2",
102102
"reflux": "^0.4.1",
103103
"semver": "^7.6.3"

packages/compass-crud/src/stores/crud-store.spec.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ describe('store', function () {
24132413
);
24142414
});
24152415

2416-
it('should keep user projection when provided', async function () {
2416+
it('should keep user fields when provided', async function () {
24172417
await fetchDocuments(
24182418
dataService,
24192419
track,
@@ -2422,13 +2422,25 @@ describe('store', function () {
24222422
'test.test',
24232423
{},
24242424
{
2425-
projection: { _id: 1 },
2425+
projection: { _id: 1, pineapple: 1 },
2426+
hint: 'pineapple',
2427+
limit: 10,
2428+
skip: 7,
2429+
sort: { pineapple: 1 },
24262430
}
24272431
);
24282432
expect(find).to.have.been.calledOnce;
24292433
expect(find.getCall(0))
24302434
.to.have.nested.property('args.2.projection')
2431-
.deep.eq({ _id: 1 });
2435+
.deep.eq({ _id: 1, pineapple: 1 });
2436+
expect(find.getCall(0)).to.have.nested.property('args.2.limit').eq(10);
2437+
expect(find.getCall(0)).to.have.nested.property('args.2.skip').eq(7);
2438+
expect(find.getCall(0))
2439+
.to.have.nested.property('args.2.sort')
2440+
.deep.eq({ pineapple: 1 });
2441+
expect(find.getCall(0))
2442+
.to.have.nested.property('args.2.hint')
2443+
.eq('pineapple');
24322444
});
24332445

24342446
it('should retry find operation if failed with server error when applying custom projection', async function () {

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import type {
6868
} from '@mongodb-js/compass-connections/provider';
6969
import type { Query, QueryBarService } from '@mongodb-js/compass-query-bar';
7070
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
71-
import type { MongoServerError } from 'mongodb';
71+
import type { CollationOptions, MongoServerError } from 'mongodb';
7272

7373
export type BSONObject = TypeCastMap['Object'];
7474
export type BSONArray = TypeCastMap['Array'];
@@ -589,7 +589,7 @@ class CrudStoreImpl
589589
if (id !== undefined) {
590590
doc.onRemoveStart();
591591
try {
592-
await this.dataService.deleteOne(this.state.ns, { _id: id } as any);
592+
await this.dataService.deleteOne(this.state.ns, { _id: id as any });
593593
// emit on the document(list view) and success state(json view)
594594
doc.onRemoveSuccess();
595595
const payload = { view: this.state.view, ns: this.state.ns };
@@ -866,6 +866,7 @@ class CrudStoreImpl
866866
filter,
867867
limit,
868868
sort,
869+
hint,
869870
project: projection,
870871
collation,
871872
maxTimeMS,
@@ -894,9 +895,10 @@ class CrudStoreImpl
894895
const opts = {
895896
skip,
896897
limit: nextPageCount,
897-
sort,
898-
projection,
899-
collation,
898+
hint: hint ?? undefined,
899+
sort: sort ?? undefined,
900+
projection: projection ?? undefined,
901+
collation: collation as CollationOptions,
900902
maxTimeMS: capMaxTimeMSAtPreferenceLimit(this.preferences, maxTimeMS),
901903
promoteValues: false,
902904
bsonRegExp: true,
@@ -920,7 +922,7 @@ class CrudStoreImpl
920922
this.state.isDataLake,
921923
ns,
922924
filter ?? {},
923-
opts as any,
925+
opts,
924926
{
925927
abortSignal: signal,
926928
}
@@ -1649,9 +1651,14 @@ class CrudStoreImpl
16491651
: query.maxTimeMS
16501652
),
16511653
signal,
1654+
...(query.hint
1655+
? {
1656+
hint: query.hint,
1657+
}
1658+
: {}),
16521659
};
16531660

1654-
if (this.isCountHintSafe(query)) {
1661+
if (!countOptions.hint && this.isCountHintSafe(query)) {
16551662
countOptions.hint = '_id_';
16561663
}
16571664

@@ -1671,11 +1678,12 @@ class CrudStoreImpl
16711678
}
16721679

16731680
const findOptions = {
1674-
sort,
1675-
projection: query.project,
1681+
sort: sort ?? undefined,
1682+
projection: query.project ?? undefined,
16761683
skip: query.skip,
16771684
limit: docsPerPage,
1678-
collation: query.collation,
1685+
collation: query.collation as CollationOptions,
1686+
hint: query.hint ?? undefined,
16791687
maxTimeMS: capMaxTimeMSAtPreferenceLimit(
16801688
this.preferences,
16811689
query.maxTimeMS
@@ -1705,7 +1713,7 @@ class CrudStoreImpl
17051713
// Only check if index was used if query filter or sort is not empty
17061714
if (!isEmpty(query.filter) || !isEmpty(query.sort)) {
17071715
void this.dataService
1708-
.explainFind(ns, query.filter ?? {}, findOptions as any, {
1716+
.explainFind(ns, query.filter ?? {}, findOptions, {
17091717
explainVerbosity: 'queryPlanner',
17101718
abortSignal: signal,
17111719
})
@@ -1772,7 +1780,7 @@ class CrudStoreImpl
17721780
this.state.isDataLake,
17731781
ns,
17741782
query.filter ?? {},
1775-
findOptions as any,
1783+
findOptions,
17761784
{
17771785
abortSignal: signal,
17781786
}

packages/compass-editor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@lezer/highlight": "^1.2.1",
7575
"@mongodb-js/compass-components": "^1.59.1",
7676
"@mongodb-js/mongodb-constants": "^0.17.0",
77-
"mongodb-query-parser": "^4.3.0",
77+
"mongodb-query-parser": "^4.5.0",
7878
"polished": "^4.2.2",
7979
"prettier": "^2.7.1",
8080
"react": "^17.0.2"

packages/compass-export-to-language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@mongodb-js/compass-editor": "^0.61.1",
5555
"@mongodb-js/compass-maybe-protect-connection-string": "^0.64.2",
5656
"@mongodb-js/compass-telemetry": "^1.19.4",
57-
"@mongodb-js/shell-bson-parser": "^1.2.0",
57+
"@mongodb-js/shell-bson-parser": "^1.3.3",
5858
"bson-transpilers": "^3.2.23",
5959
"compass-preferences-model": "^2.66.2",
6060
"@mongodb-js/compass-app-registry": "^9.4.28",

packages/compass-import-export/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"mongodb": "^6.19.0",
6868
"mongodb-data-service": "^22.35.0",
6969
"mongodb-ns": "^3.0.1",
70-
"mongodb-query-parser": "^4.3.0",
70+
"mongodb-query-parser": "^4.5.0",
7171
"mongodb-schema": "^12.6.3",
7272
"papaparse": "^5.3.2",
7373
"react": "^17.0.2",

packages/compass-indexes/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"@mongodb-js/compass-telemetry": "^1.19.4",
7777
"@mongodb-js/compass-workspaces": "^0.69.2",
7878
"@mongodb-js/mongodb-constants": "^0.17.0",
79-
"@mongodb-js/shell-bson-parser": "^1.2.0",
79+
"@mongodb-js/shell-bson-parser": "^1.3.3",
8080
"@mongodb-js/connection-info": "^0.23.0",
8181
"bson": "^6.10.4",
8282
"compass-preferences-model": "^2.66.2",
@@ -85,7 +85,7 @@
8585
"mongodb-collection-model": "^5.36.0",
8686
"mongodb-data-service": "^22.35.0",
8787
"mongodb-ns": "^3.0.1",
88-
"mongodb-query-parser": "^4.3.0",
88+
"mongodb-query-parser": "^4.5.0",
8989
"react": "^17.0.2",
9090
"react-redux": "^8.1.3",
9191
"redux": "^4.2.1",

packages/compass-query-bar/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"mongodb": "^6.19.0",
8585
"mongodb-instance-model": "^12.58.2",
8686
"mongodb-ns": "^3.0.1",
87-
"mongodb-query-parser": "^4.3.0",
87+
"mongodb-query-parser": "^4.5.0",
8888
"mongodb-query-util": "^2.5.12",
8989
"mongodb-schema": "^12.6.3",
9090
"react": "^17.0.2",

0 commit comments

Comments
 (0)