Files
mongo/jstests/aggregation/sources/setWindowFields/avoid_express_path.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

34 lines
998 B
JavaScript

/**
* Test that when $setWindowFields requires metadata, it does not take the express path
* even if the desugared query would otherwise be eligible.
* @tags: [requires_fcv_82]
*/
import {getQueryPlanner, planHasStage} from "jstests/libs/query/analyze_plan.js";
const coll = db[jsTestName()];
coll.drop();
const documents = [
{
_id: 31,
date: 2,
},
];
assert.commandWorked(coll.insert(documents));
// We need a sort key, but the point _id query would normally take the express path.
let q = [
{"$match": {"_id": 31}},
{
"$setWindowFields": {"sortBy": {"date": 1}, "partitionBy": "$array", "output": {"x": {"$denseRank": {}}}},
},
];
// This query should return one successfully ranked document.
let result = coll.aggregate(q).toArray();
assert.eq(result, [{_id: 31, date: 2, x: 1}]);
let explain = coll.explain().aggregate(q);
let planner = getQueryPlanner(explain);
assert(planHasStage(db, planner.winningPlan, "SORT_KEY_GENERATOR"), planner);