Files
mongo/jstests/aggregation/sources/project/large_project.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

50 lines
1.3 KiB
JavaScript

/**
* Tests that $projects with a large number of projected fields behave as expected.
*/
(function () {
const coll = db.large_project;
coll.drop();
const numProjects = 10000;
const doc = {
_id: 15,
};
for (let i = 0; i < numProjects; i++) {
doc["a" + i] = i;
}
assert.commandWorked(coll.insert(doc));
{
// Inclusion projection.
const project = {};
const expectedDoc = {_id: 15};
for (let i = 0; i < numProjects; i++) {
if (i % 2 === 1) {
project["a" + i] = 1;
expectedDoc["a" + i] = i;
}
}
const result = coll.aggregate({$project: project}).toArray();
assert.eq(result.length, 1);
assert.docEq(result[0], expectedDoc);
}
{
// Exclusion projection.
const project = {};
const expectedDoc = {_id: 15};
for (let i = 0; i < numProjects; i++) {
if (i % 2 === 0) {
project["a" + i] = 0;
} else {
expectedDoc["a" + i] = i;
}
}
const result = coll.aggregate({$project: project}).toArray();
assert.eq(result.length, 1);
assert.docEq(result[0], expectedDoc);
}
})();