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(NODE-6504): Add Double as a SchemaType #15061

Merged
merged 9 commits into from
Dec 9, 2024

Conversation

aditi-khare-mongoDB
Copy link
Contributor

Summary

Motivation
Support a IEEE 754-2008 floating point type in mongoose for compatibility with CSFLE/QE. The current Number schema type can result in either Int32, Int64, or Doubles that are inserted into the database using type inference but CSFLE and QE require exact BSON types in schemas.

The reason the Double constructor returns a BSON.Double is so even when an integer is inserted, the field is still queryable as a $double:

  await Test.create({ myDouble: '42' });
  const doc = await Test.findOne({ myDouble: { $type: 'double' } });
  assert.deepEqual(doc.myDouble, new BSON.Double(42));

Summary of Changes

  • Same changes as NODE-6503 but for Double.
  • Add SchemaType Double, which has the following behavior:
    • its default cast method throws when provided a
      • a non-numeric string
    • it is queryable as $type: double or $type: number
  • Add API Docs for new query option and new schema type

Example

const vehicleSchema = new Schema({ gasLevel: mongoose.Schema.Types.Double });

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Merging into 8.9

@vkarpov15 vkarpov15 changed the base branch from master to 8.9 December 9, 2024 16:26
@vkarpov15
Copy link
Collaborator

There's some test failures and lint issues from merge conflicts, I'll fix those in the 8.9 branch

@vkarpov15 vkarpov15 merged commit 7d25b48 into Automattic:8.9 Dec 9, 2024
41 of 43 checks passed
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.

2 participants