Skip to content

Conversation

@vkarpov15
Copy link
Collaborator

@vkarpov15 vkarpov15 commented Nov 29, 2025

Summary

Right now, only container types that extend from Mongoose arrays can take advantage of atomics (change tracking so, for example, push() translates to $push in save()). That's problematic for trying to implement custom types like Sets.

This PR makes Mongoose look for a getAtomics() function on values, so custom types can use atomics without having to implement an internal method like $__atomics().

Similarly, I added clearAtomics() which allows Mongoose to clear custom types' atomics after successful save

Examples

Copy link
Contributor

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 adds support for custom container types (like Sets) to utilize Mongoose's atomic operations tracking without needing to extend from MongooseArray. It introduces a new public getAtomics() method that custom types can implement to provide atomic operations during document save.

Key changes:

  • Added public getAtomics() method to MongooseArray as an alias for $__getAtomics()
  • Modified document save logic to check for getAtomics() function instead of MongooseArray-specific properties
  • Enabled custom container types to participate in atomic operations by implementing getAtomics()

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lib/types/array/methods/index.js Adds public getAtomics() method to MongooseArray as an API for custom types
lib/document.js Updates $__delta and handleAtomics to detect and use getAtomics() for atomic operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vkarpov15 vkarpov15 changed the base branch from 8.x to 8.21 December 1, 2025 22:32
@vkarpov15 vkarpov15 merged commit 5471485 into 8.21 Dec 1, 2025
74 checks passed
@hasezoey hasezoey deleted the vkarpov15/get-atomics branch December 2, 2025 10:33
@vkarpov15 vkarpov15 restored the vkarpov15/get-atomics branch December 29, 2025 16:11
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.

4 participants