@@ -145,19 +145,19 @@ private static String generateRemoteSchema(String keyId, int numFields) {
145145 return "{ $jsonSchema : " + generateSchema (keyId , numFields ) + "}" ;
146146 }
147147
148- private static synchronized String getDataKeyOrCreate (MongoCollection <Document > keyCollection , ClientEncryption clientEncryption ) {
149- Document findFilter = new Document ();
150- Document keyDoc = keyCollection .find (findFilter ).first ();
151-
148+ private static synchronized String getDataKeyOrCreate (MongoCollection <BsonDocument > keyCollection , ClientEncryption clientEncryption ) {
149+ BsonDocument findFilter = new BsonDocument ();
150+ BsonDocument keyDoc = keyCollection .find (findFilter ).first ();
151+
152152 String base64DataKeyId ;
153- if (keyDoc == null ) {
153+ if (keyDoc == null ) {
154154 BsonBinary dataKeyId = clientEncryption .createDataKey ("local" , new DataKeyOptions ());
155155 base64DataKeyId = Base64 .getEncoder ().encodeToString (dataKeyId .getData ());
156156 } else {
157- UUID dataKeyId = ( UUID ) keyDoc .get ("_id" );
157+ UUID dataKeyId = keyDoc .getBinary ("_id" ). asUuid ( );
158158 base64DataKeyId = Base64 .getEncoder ().encodeToString (UuidUtils .asBytes (dataKeyId ));
159159 }
160-
160+
161161 return base64DataKeyId ;
162162 }
163163
@@ -196,7 +196,7 @@ private static AutoEncryptionSettings generateEncryptionSettings(String url, Boo
196196
197197 MongoClient vaultClient = MongoClients .create (keyVaultUrls );
198198
199- final MongoCollection <Document > keyCollection = vaultClient .getDatabase (database ).getCollection (keyVaultNamespace );
199+ final MongoCollection <BsonDocument > keyCollection = vaultClient .getDatabase (database ).getCollection (keyVaultNamespace , BsonDocument . class );
200200
201201 String base64DataKeyId = getDataKeyOrCreate (keyCollection , clientEncryption );
202202
0 commit comments