Alterantive for distinct in queryable encryption

How to do .distinct() operations in queryable encryption enabled collections

when using queryable encrypted collections, how can we perform .distinct() operation . How can we do grouping in aggregation in the encrypted fields ( _id : ‘$encryptedField’)

Hey @Bijith_K,

Welcome to the MongoDB Community :sparkles:

Could you please share some more details about your use case so the community can assist you better?

For example,

  • The sample document and
  • The operation you want to perform as well as
  • The expected output documents
  • Also, share the version of MongoDB that is being used.

Meanwhile, you can refer to the Supported Operations for Queryable Encryption documentation to learn more about it.

Best regards,
Kushagra

Yeah sure,
Sample document will be like,
[{name: …, email: …, city: …, state:… , date: 1512691200000, age: 20},{name: …, email:… , city: … ,state: …, date: 1666137600000, age: 23}]

In this collection, the name,email,city and state fields are encrypted.

From this document, i need to find unique cities.
If this was not a queryable encryption enabled collection , I can get result using the below query,
collection.distinct( “city” ).

But this collection is a queryable encryption enabled one. So this will not work.

I am expecting an output from the query is , [‘city1’,‘city2’].

I am using the Node.js driver for MongoDB.
My MongoDB version is 6.1.0

@Kushagra_Kesav , here is the detailed information regarding my query