Skip to content

Commit 5dbf929

Browse files
authored
[mongoose] Added connection options related to auto encryption using CSFLE (DefinitelyTyped#43723)
* added new connection options related to the new feature csfle * added basic test case for auto-encryption in mongoose client connection
1 parent f00facd commit 5dbf929

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

types/mongoose/index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
// Dongjun Lee <https://github.com/ChazEpps>
3838
// Valentin Agachi <https://github.com/avaly>
3939
// Jan Nemcik <https://github.com/JanNemcik>
40+
// Cl3dson <https://github.com/cl3dson>
4041
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
4142
// TypeScript Version: 3.0
4243

@@ -395,6 +396,15 @@ declare module "mongoose" {
395396
* is set to true.(default: false) */
396397
autoCreate?: boolean;
397398

399+
400+
/** Configure csfle as especified in MongoDB official guide */
401+
autoEncryption?: {
402+
keyVaultNamespace: string,
403+
kmsProviders: any,
404+
schemaMap: any,
405+
extraOptions?: any
406+
}
407+
398408
/** Specify a journal write concern (default: false). */
399409
journal?: boolean;
400410

types/mongoose/mongoose-tests.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ const connection3 = mongoose.connect(connectUri, function (error) {
3737
error.stack;
3838
});
3939

40+
/**
41+
* Test taken from MongoDB CSFLE guide
42+
* https://docs.mongodb.com/drivers/use-cases/client-side-field-level-encryption-guide
43+
*/
44+
45+
const connection4:Promise<mongoose.Mongoose> = mongoose.connect(connectUri,{
46+
useNewUrlParser: true,
47+
useUnifiedTopology: true,
48+
autoEncryption: {
49+
keyVaultNamespace: 'encryption.__keyVault',
50+
kmsProviders: {},
51+
schemaMap: {},
52+
extraOptions: {}
53+
}
54+
})
55+
4056
var mongooseConnection: mongoose.Connection = mongoose.createConnection();
4157
mongooseConnection.dropDatabase().then(()=>{});
4258
mongooseConnection.dropCollection('foo').then(()=>{});

0 commit comments

Comments
 (0)