Skip to content

Compare documented projections and convert the cases that use them - #4576

Open
evanchooly wants to merge 1 commit into
audits-indexesfrom
audits-projections
Open

evanchooly wants to merge 1 commit into
audits-indexesfrom
audits-projections

Conversation

@evanchooly

Copy link
Copy Markdown
Member

One of the plan's deferred cutover features. Stacked on #4575.

Problem

Two cases were legacy-only with "the page documents a projection, which needs the unmapped findOptions":

db.inventory.find( { quantity: { $in: [ 5, 15 ] } }, { _id: 0 } )

The scenario format had no place for a projection, and conversion refused one. The runner also refused any converted test that passed findOptions. The legacy tests approximated {_id: 0} with removeIds(true), which strips _id from the results instead of projecting it away.

Change

  • Scenario: a find action carries projection when the page documents one.

  • Runner: a new find(case, dsl, FindOptions) builds the query from those options. It:

    • compares [filter, projection] with Morphia's query and the mapped FindOptions projection, strictly, after the declared rules;
    • runs the projected query on both sides.

    The existing find overloads delegate to it.

  • Converted tests: findOptions is now a mapped legacy option. It changes nothing in the scenario, since the projection comes from the page. A test may pass it only when the scenario has a projection; any non-projection option would change the results, which the behavior check compares with the documented query's.

  • Converted cases:

    • $in useTheInOperatorToMatchValues and $nin selectOnUnmatchingDocuments: each body gains findOptions(new FindOptions().projection().exclude("_id")), recorded in the ledger as a reviewed body edit;
    • $text relevanceScoreExamples: became convertible once findOptions was mapped, and passes unchanged;
    • $rand selectRandomItemsFromACollection stays legacy-only, with its failing check recorded. The page projects {_id: 0, name: 1, registered: 1}, but the test includes name and registered and drops _id with removeIds, so its projection lacks the _id exclusion. Fixing it means combining an _id exclusion with inclusions in the page's key order, which belongs in its own change.

Result

373 legacy cases are on the runner, 183 legacy directories are left, and 15 cases are legacy-only.

Decisions for review

  • Keep removeIds(true) beside the projection in the two edited bodies. It's now redundant, but keeping it leaves their scenarios exactly as converted.
  • The generator still gaps on documented projections. Emitting projections there runs into the same _id-exclusion question as $rand.

Verification

  • TestIn, TestNin, TestText and TestRand pass under Critter, then reflection.
  • Core operator tests: 692 pass under both mappers.
  • Audits suite: 458 pass under both mappers. The ledger, the frozen-catalog body-edit check and the cutover completeness check all hold.

Self-reviewed only: the independent reviewers are out of quota until 2026-11-26.

A find scenario carries the page's projection, and the runner compares
Morphia's projection with it after the filter, then runs the projected
query on both sides. Converted tests pass their legacy findOptions, now a
mapped option. The $in and $nin cases convert after their bodies gain
the page's _id exclusion, recorded as reviewed edits, and $text's
relevance-score case converts unchanged; $rand's stays legacy-only
because its test omits the _id exclusion the page projects.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant