Skip to content

Unable to Create Encrypted Collection with Floating Point Range (precision, min, max not respected) #4989

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

Closed
ricardohsmello opened this issue Jun 2, 2025 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@ricardohsmello
Copy link
Contributor

Hi team,

I’ve been working with Spring Data MongoDB 4.5.0 and the new support for Queryable Encryption, and I’m encountering an issue when trying to create an encrypted collection with a double field using range encryption.

Here’s the code snippet:

    private static void manualCollectionSetup(ClientEncryption clientEncryption, MongoOperations mongoTemplate) {
        BsonBinary dkSalary = clientEncryption.createDataKey("local", new com.mongodb.client.model.vault.DataKeyOptions().keyAltNames(List.of("salary")));

        CollectionOptions collectionOptions = CollectionOptions.encryptedCollection(options -> options
                .queryable(encrypted(float64("salary")).algorithm("Range").keyId(dkSalary.asUuid()), range().contention(0).precision(2).min(0.0).max(9999.0))
        );

        mongoTemplate.createCollection(Employee.class, collectionOptions);
    }

I'm getting:

Caused by: com.mongodb.MongoCommandException: Command failed with error 6967100 (Location6967100): 'Precision, min, and max must all be specified together for floating point fields' on server localhost:27020. The full response is {"ok": 0.0, "errmsg": "Precision, min, and max must all be specified together for floating point fields", "code": 6967100, "codeName": "Location6967100"}

I believe this suggests that the Spring Data is not sending these parameters (precision, min, max) properly when creating the collection for floating point fields.

I’m happy to share a full minimal reproducible example if needed.

Thank you for the help!

@christophstrobl
Copy link
Member

christophstrobl commented Jun 4, 2025

Good catch @ricardohsmello - precision is missing in the target options. We'll fix that.

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 4, 2025
@mp911de mp911de added this to the 4.5.1 (2025.0.1) milestone Jun 4, 2025
@mp911de mp911de closed this as completed in 5d5e474 Jun 4, 2025
mp911de pushed a commit that referenced this issue Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants