Skip to content

Commit 642c5b5

Browse files
add is pipleine search queryable method
1 parent 432a555 commit 642c5b5

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

packages/compass-aggregations/src/components/stage-toolbar/stage-operator-select.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,37 @@ type StageOperatorSelectProps = {
4545
}[];
4646
serverVersion: string;
4747
isReadonlyView: boolean;
48-
pipelineBuilder: any;
48+
pipeline: any;
49+
fetchEffectivePipeline: () => void;
50+
};
51+
52+
const isPipelineSearchQueryable = (
53+
pipeline: Array<Record<string, any>>
54+
): boolean => {
55+
for (const stage of pipeline) {
56+
const stageKey = Object.keys(stage)[0];
57+
58+
if (
59+
!(
60+
stageKey === '$addFields' ||
61+
stageKey === '$set' ||
62+
stageKey === '$match'
63+
)
64+
) {
65+
return false;
66+
}
67+
68+
if (stageKey === '$match') {
69+
const matchStage = stage['$match'];
70+
const allKeys = Object.keys(matchStage);
71+
72+
if (!(allKeys.length === 1 && allKeys.includes('$expr'))) {
73+
return false; // Not searchable
74+
}
75+
}
76+
}
77+
78+
return true;
4979
};
5080

5181
// exported for tests
@@ -54,10 +84,9 @@ export const StageOperatorSelect = ({
5484
index,
5585
selectedStage,
5686
isDisabled,
57-
stages,
5887
serverVersion,
5988
isReadonlyView,
60-
pipelineBuilder,
89+
stages,
6190
}: StageOperatorSelectProps) => {
6291
const onStageOperatorSelected = useCallback(
6392
(name: string | null) => {
@@ -71,9 +100,18 @@ export const StageOperatorSelect = ({
71100
env: ServerEnvironment[];
72101
description: string;
73102
}) => {
74-
//const mongoDBMajorVersion = parseFloat(serverVersion.split('.').slice(0, 2).join('.'));
75103
if (isSearchStage(stage.name)) {
76-
return `${serverVersion} ${isReadonlyView}Atlas only. Requires MongoDB 8.1+ to run on a view. Performs a full-text search on the specified fields.`;
104+
// check if server version>8.0 and isReadonlyView after editing stages file
105+
if (isPipelineSearchQueryable([])) {
106+
return (
107+
`Atlas only. Requires MongoDB 8.1+ to run on a view. ` +
108+
stage.description
109+
);
110+
}
111+
return (
112+
`Atlas only. Only views containing $addFields, $set or $match stages with the $expr operator are compatible with search indexes.` +
113+
stage.description
114+
);
77115
}
78116
return (isAtlasOnly(stage.env) ? 'Atlas only. ' : '') + stage.description;
79117
};
@@ -133,7 +171,6 @@ export default withPreferences(
133171
stages: stages,
134172
serverVersion: state.serverVersion,
135173
isReadonlyView: !!state.sourceName,
136-
pipelineBuilder: state.pipelineBuilder,
137174
};
138175
},
139176
(dispatch: any, ownProps) => {

0 commit comments

Comments
 (0)