Skip to content

MONGOID-5213 Document changes to BigDecimal type and addition of global flag #5126

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

Merged
merged 9 commits into from
Jan 13, 2022

Conversation

neilshweky
Copy link
Contributor

@neilshweky neilshweky commented Jan 6, 2022

Screen Shot 2022-01-11 at 10 14 44 AM

Screen Shot 2022-01-11 at 10 14 33 AM

@neilshweky neilshweky requested a review from p-mongo January 6, 2022 20:33
@neilshweky neilshweky changed the title MONGOID-5213 Document changes to BigDecimal type and addition of global flag MONGOID-5213 MONGOID-5212 Document changes to BigDecimal type and addition of global flag Jan 6, 2022
@neilshweky neilshweky requested a review from comandeo January 7, 2022 15:52
@neilshweky neilshweky requested a review from p-mongo January 7, 2022 17:03
not find the string for that ``BigDecimal``, since the query is looking for a
``BigDecimal``. In order to query for that string, the ``BigDecimal`` must
first be converted to a string with ``to_s``. Note that this is not a problem
when the field has type ``BigDecimal``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would BigDecimal-typed field have the same issue in the other direction - when querying existing data that is stored as strings after Mongoid.map_big_decimal_to_decimal128 is set to true, nothing would be found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that is true as well... How would you like to handle this case?

Copy link
Contributor

@johnnyshields johnnyshields Jan 10, 2022

Choose a reason for hiding this comment

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

It should be documented in the release notes and options documentation for map_big_decimal_to_decimal128. It should make clear that when switching the flag, it will break the ability to query against existing data, and that all data must be migrated.

Fortunately, in the real-world, applications are very unlikely to be doing any queries on BigDecimal as string today, because it's pretty useless--you'd can only match against exact values. In other worlds, if you have field :money_amt, type: BigDecimal, then .gt(money_amt: 100) will NOT work today. The valid cases are:

  • .where(money_amt: 100) --> pretty unlikely to do for money-type use cases.
  • .ne(money_amt: nil) --> will work regardless of string or decimal128.

Hence this migration should be easy in practice. (I use BigDecimal on at least 50 fields in my app and I don't have any queries against it; I only use it for persisting data which is retrieved via other queries.)

The ``BigDecimal`` field type is used to store numbers with increased precision.

The ``BigDecimal`` field type stores its values in two different ways under the
hood, depending on the value of the ``Mongoid.map_big_decimal_to_decimal128``
Copy link
Contributor

Choose a reason for hiding this comment

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

under the hood --> in the database

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kind of like it the way it is tbh...

Copy link
Contributor

Choose a reason for hiding this comment

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

"Under the hood":

  • Does not clearly indicate under which "hood" -- is it in Ruby's memory or the database?
  • Is idiomatic English which does not make sense to non-native speakers (Mongoid is not a car :) )

It's good to think about these points when writing technical documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, if you really think so I'll change it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


.. note::
In Mongoid 7.6, the global config ``Mongoid.map_big_decimal_to_decimal128``
will be defaulted to true instead of false.
Copy link
Contributor

@johnnyshields johnnyshields Jan 9, 2022

Choose a reason for hiding this comment

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

Following Semver, this default change should take place in Mongoid 8.0, NOT 7.6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@p-mongo and I discussed this. He didn't want to release a major version for this... @p-mongo thoughts?

Copy link
Contributor

@johnnyshields johnnyshields Jan 10, 2022

Choose a reason for hiding this comment

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

Read this article: https://serpapi.com/blog/how-a-routine-gem-update-ended-up-charging/ and tell me your thoughts. Also please read the SemVer spec https://semver.org/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey we've seen this and we're reconsidering how we want to version this... Thanks!

@neilshweky neilshweky requested a review from p-mongo January 10, 2022 14:10
Copy link
Contributor

@p-mongo p-mongo left a comment

Choose a reason for hiding this comment

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

👍

@neilshweky neilshweky changed the title MONGOID-5213 MONGOID-5212 Document changes to BigDecimal type and addition of global flag MONGOID-5213 Document changes to BigDecimal type and addition of global flag Jan 13, 2022
@neilshweky neilshweky merged commit 339583a into mongodb:master Jan 13, 2022
p-mongo pushed a commit to johnnyshields/mongoid that referenced this pull request Jan 21, 2022
* master:
  MONGOID-5098 Bug fix: Range.mongoize should mongoize its members (mongodb#5108)
  MONGOID-5212 Support for Decimal128 type (mongodb#5125)
  MONGOID-5213 Document changes to BigDecimal type and addition of global flag (mongodb#5126)
  MONGOID-5209 Document "Custom Field Options" functionality + various docs improvements (mongodb#5120)
  MONGOID-5193 rails 7 support  (mongodb#5122)
  Fix default topology name - should be standalone (mongodb#5130)
  Update MRSS (mongodb#5129)
  MONGOID-5207 Test Ruby 3.1 on Evergreen (mongodb#5123)
  MONGOID-5186 .with_scope should restore previous scope (mongodb#5127)
  MONGOID-5161 - [Documentation Only] Clarify the policy for working with . and $ named fields which were introduced in MongoDB 5.0 (mongodb#5051)
p-mongo pushed a commit to johnnyshields/mongoid that referenced this pull request Jan 21, 2022
* master: (48 commits)
  MONGOID-5098 Bug fix: Range.mongoize should mongoize its members (mongodb#5108)
  MONGOID-5212 Support for Decimal128 type (mongodb#5125)
  MONGOID-5213 Document changes to BigDecimal type and addition of global flag (mongodb#5126)
  MONGOID-5209 Document "Custom Field Options" functionality + various docs improvements (mongodb#5120)
  MONGOID-5193 rails 7 support  (mongodb#5122)
  Fix default topology name - should be standalone (mongodb#5130)
  Update MRSS (mongodb#5129)
  MONGOID-5207 Test Ruby 3.1 on Evergreen (mongodb#5123)
  MONGOID-5186 .with_scope should restore previous scope (mongodb#5127)
  MONGOID-5161 - [Documentation Only] Clarify the policy for working with . and $ named fields which were introduced in MongoDB 5.0 (mongodb#5051)
  MONGOID-5173 Specs should use bang (!) methods (without describe/context change) (mongodb#5109)
  Fix doc syntax
  RUBY-2783 Require bson 4-stable for Mongoid as bson master is 5.0 and not compatible with driver (mongodb#5113)
  MONGOID-5208 fix error on reloading nil embedded document (mongodb#5116)
  MONGOID-5206 fix bug where embedded document is not re-embedded (mongodb#5115)
  MONGOID-5207 Add Ruby 3.1 to GH Actions (mongodb#5114)
  MONGOID-5207 Use YAML.safe_load in specs (mongodb#5112)
  MONGOID-5199 Reloadable#reload_embedded_document doesn't respect session (mongodb#5105)
  Fix MONGOID-5198 Calling children_changed? on a deep cyclical data structure will cause semi-infinite looping (mongodb#5104)
  MONGOID-5203 Add all available auth_mech options to Configuration documentation (mongodb#5103)
  ...
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