[MONGOCRYPT-504] Add support for $in, $eq for range indexes for explicit encryption Created: 01/Dec/22  Updated: 14/Mar/23

Status: Backlog
Project: Libmongocrypt
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Gil Alon Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: rb-track
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Binding Changes: Not Needed

 Description   

Range indexes should support queries that use the $in and $eq operator in explicit encryption. Trying to encrypt the query below with explicit encryption on an encrypted index of type double raises an error.

"{ '$and': [{ 'encryptedDoublePrecision': { '$in': [{ '$numberDouble': '0.0' }, { '$numberDouble': '10.0' }] } } ] });"

The error message raised was: 

 unsupported operator: $in: { "$and" : [ { "encryptedDoublePrecision" : { "$in" : [ { "$numberDouble" : "0.0" }, { "$numberDouble" : "10.0" } ] } } ] }

The same error is raised for the $eq operator.



 Comments   
Comment by Kevin Albertson [ 03/Dec/22 ]

mongocryptd rewrites "$eq" and "$in" expressions using "$gte" and "$lte" of the same value.

E.g.

{"value": {"$eq": 123}}

is rewritten as

{"$and": [{"value": {"$gte": 123}}, {"value": {"$lte": 123 }}]}

And:

{"value": {"$in": [123, 124]}}

is rewritten as

{"$or": [
    {"$and": [{"value": {"$gte": 123}}, {"value": {"$lte": 123 }}]}
    {"$and": [{"value": {"$gte": 124}}, {"value": {"$lte": 124 }}]}
]}

The existing output can be used to build the same expressions:

# Do an equality match for value 123.
got = clientEncryption.encryptExpression ({"$and": [{"value": {"$gte": 123, {"value": {"$lte": 123 }}]}, opts)
coll.find_one (got)

Updating to mark as a "New Feature". There is a workaround. Supporting "$eq" and "$in" in explicit encryption may be a useful convenience.

Generated at Thu Feb 08 09:08:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.