Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support dot notation on array fields #9115

Draft
wants to merge 3 commits into
base: alpha
Choose a base branch
from

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented May 2, 2024

Pull Request

Issue

Currently all dot notations are treated as operations on Object type field. This results in a error: Cannot read property '0' of undefined when used on Array type fields.

Closes: #6687

Approach

Check types for Array vs Fields based on dot notation format.

https://www.mongodb.com/docs/manual/core/document/#dot-notation

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

Copy link

Thanks for opening this pull request!

@dplewis dplewis requested a review from a team May 2, 2024 16:16
Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.14%. Comparing base (f1469c6) to head (201993f).
Report is 13 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #9115   +/-   ##
=======================================
  Coverage   94.13%   94.14%           
=======================================
  Files         186      186           
  Lines       14687    14727   +40     
=======================================
+ Hits        13826    13864   +38     
- Misses        861      863    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mtrezza mtrezza changed the title feat: Support dot notation on Array fields feat: Support dot notation on array fields May 3, 2024
obj.set('items', [ { value: 'a', count: 5 }, { value: 'b', count: 1 } ]);
await obj.save();

obj.increment('items.0.count', 15);
Copy link
Member

Choose a reason for hiding this comment

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

Is this notation MongoDB specific? If so, this may not be clear for developers who use Postgres. Should this notation be documented?

Copy link
Member Author

Choose a reason for hiding this comment

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

I got dot notation working on PG years ago. Adding Array support might be possible.

Copy link
Member

Choose a reason for hiding this comment

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

It's not a requirement for this PR to add support for PG, I was just referring to the syntax itself, whether that is commonly known or should be documented.

@dplewis
Copy link
Member Author

dplewis commented May 5, 2024

@mtrezza This is an extremely complicated feature. I tried running this with the SDK internal fix against the server test suite and got Array dot notation working but it somehow broke the server. I’ll let you know when this is ready for review.

@mtrezza mtrezza marked this pull request as draft May 6, 2024 00:32
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.

How to increment array nested object field?
2 participants