I found an error when trying to use Mongodb's queryable encryption

I tried to use the queryable encryption function of MongoDB according to the official documents(Quick Start of Queryable Encryption), and copied the Complete Python Application example to run on my local computer.However, an error occurred during the compilation of the make_data_key.py.

The error message is as follows:

Traceback (most recent call last):
  File "D:\Python\project\MongoDBtest\make_data_key.py", line 119, in <module>
    encrypted_db.create_collection(encrypted_coll_name)
  File "D:\Python\Python\lib\site-packages\pymongo\_csot.py", line 105, in csot_wrapper
    return func(self, *args, **kwargs)
  File "D:\Python\Python\lib\site-packages\pymongo\database.py", line 448, in create_collection
    return Collection(
  File "D:\Python\Python\lib\site-packages\pymongo\collection.py", line 232, in __init__
    self.__create(name, kwargs, collation, session, encrypted_fields=encrypted_fields)
  File "D:\Python\Python\lib\site-packages\pymongo\collection.py", line 313, in __create
    self._command(
  File "D:\Python\Python\lib\site-packages\pymongo\collection.py", line 285, in _command
    return sock_info.command(
  File "D:\Python\Python\lib\site-packages\pymongo\pool.py", line 766, in command
    return command(
  File "D:\Python\Python\lib\site-packages\pymongo\network.py", line 166, in command
    helpers._check_command_response(
  File "D:\Python\Python\lib\site-packages\pymongo\helpers.py", line 181, in _check_command_response
    raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: **Encrypted collections are not supported on standalone**, full error: {'ok': 0.0, 'errmsg': 'Encrypted collections are not supported on standalone', 'code': 6346402, 'codeName': 'Location6346402'}

I wonder how to solve it.

The previous problem has been solved, and now a new problem has been discovered.

The error message is as follows:

Traceback (most recent call last):
  File "D:\Python\project\MongoDBtest\make_data_key.py", line 122, in <module>
    encrypted_db.create_collection(encrypted_coll_name)
  File "D:\Python\Python\lib\site-packages\pymongo\_csot.py", line 105, in csot_wrapper
    return func(self, *args, **kwargs)
  File "D:\Python\Python\lib\site-packages\pymongo\database.py", line 448, in create_collection
    return Collection(
  File "D:\Python\Python\lib\site-packages\pymongo\collection.py", line 229, in __init__
    self.__create(_esc_coll_name(encrypted_fields, name), opts, None, session)
  File "D:\Python\Python\lib\site-packages\pymongo\collection.py", line 313, in __create
    self._command(
  File "D:\Python\Python\lib\site-packages\pymongo\collection.py", line 285, in _command
    return sock_info.command(
  File "D:\Python\Python\lib\site-packages\pymongo\pool.py", line 766, in command
    return command(
  File "D:\Python\Python\lib\site-packages\pymongo\network.py", line 166, in command
    helpers._check_command_response(
  File "D:\Python\Python\lib\site-packages\pymongo\helpers.py", line 181, in _check_command_response
    raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: BSON field 'create.clusteredIndex' is the wrong type 'object', expected types '[bool, long, int, decimal, double'], full error: {'ok': 0.0, 'errmsg': "BSON field 'create.clusteredIndex' is the wrong type 'object', expected types '[bool, long, int, decimal, double']", 'code': 14, 'codeName': 'TypeMismatch', '$clusterTime': {'clusterTime': Timestamp(1663769177, 6), 'signature': {'hash': b'\xfa\xb3_\xbf^N\xfd\x80\xc4\x87\xe4/\xc5:\xc7\xf4\xd7\xb8\xd2\xc9', 'keyId': 7108772092992028684}}, 'operationTime': Timestamp(1663769177, 6)}

I have the exact same error, have you figured out a solution to the problem yet?

Hello yuhan_cai (and Nicklas_Wurtz) and welcome to the Community!

Queryable Encryption is not supported on standalones so you have to use either a replica set or sharded clusters, but it sounds like you got that part solved. The error you are seeing seems like it is coming from a server version that does not support clusteredIndex. What server version are you using?

3 Likes

Thank you Cynthia_Braund!

I am using an Atlas Cluster

I’ve read a bit more about Queryable Encryption on MongoDB and figured out that since I’m using the free version which unly supports version 5.0 of MongoDB, I will not be able to use Queryable Encryption. It seems that the only supported version of MongoDB which can use the feature is 6.0+.

It might be related to the error we are encounting, but I’m not sure

Hi Nicklas,

Yes, that is the problem. The free tier will have support for 6.0 in the coming weeks. In the meantiime, you can use the Community edition of MongoDB if you want to test it out but you won’t be able to use Automatic Encryption.

1 Like

Hello again Nickals,

I forgot to include a link to the docs that have tutorials on how to use Explicit Encryption, which is what you’d be using for the Community edition if that you want to explore that. https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manual-encryption/.

Thanks,

Cynthia

1 Like