Skip to content

Conversation

vkarpov15
Copy link
Collaborator

Fix #15424

Summary

Remove __v from hydrated doc and toObject() + toJSON() output if user sets versionKey: false in schema options. Looking to add this in 8.17 as a precaution.

Examples

@vkarpov15 vkarpov15 added this to the 8.17 milestone Jul 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances type tests by transitioning strict expectType checks to expectAssignable for improved flexibility and adds a new test suite (gh15494) to verify that setting versionKey: false removes __v from documents.

  • Swapped expectType to expectAssignable in schema, query, and middleware tests
  • Introduced gh15494 in schema.test.ts to test versionKey: false behavior on __v presence
  • Updated query and middleware type assertions for consistency with assignable expectations

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.

File Description
test/types/schema.test.ts Updated type assertions and added gh15494 tests
test/types/queries.test.ts Swapped expectType to expectAssignable in query
test/types/middleware.test.ts Swapped expectType to expectAssignable in middleware
test/types/middleware.preposttypes.test.ts Swapped expectType to expectAssignable across pre/post middleware
Comments suppressed due to low confidence (1)

test/types/schema.test.ts:1863

  • Add similar assertions for toJSON(), e.g. expectType<number>(docA.toJSON().__v); and expectError(docB.toJSON().__v);, since the PR description mentions toJSON() output should also omit __v when versionKey: false.
  const objA = docA.toObject();

@vkarpov15 vkarpov15 changed the base branch from master to 8.17 July 3, 2025 19:19
@vkarpov15 vkarpov15 merged commit 168eeb7 into 8.17 Jul 3, 2025
3 checks passed
@hasezoey hasezoey deleted the vkarpov15/gh-15424-2 branch July 4, 2025 08:43
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.

Schema versionKey false does not remove __v from typescript type
2 participants