@@ -960,7 +960,7 @@ srDVjIT3LsvTqw==`,
960960 return ;
961961 }
962962 expect . fail ( 'missed exception' ) ;
963- break ;
963+ // eslint-disable-next-line no-fallthrough
964964 default :
965965 throw new Error ( `unreachable ${ kmsName } ` ) ;
966966 }
@@ -1058,6 +1058,97 @@ srDVjIT3LsvTqw==`,
10581058 expect ( printedOutput ) . to . deep . equal ( [ ] ) ;
10591059 } ) ;
10601060
1061+ it ( 'allows $lookup with a collection with automatic encryption' , async function ( ) {
1062+ const keyMongo = new Mongo (
1063+ instanceState ,
1064+ uri ,
1065+ {
1066+ keyVaultNamespace : `${ dbname } .__keyVault` ,
1067+ kmsProviders : { local : { key : 'A' . repeat ( 128 ) } } ,
1068+ } ,
1069+ { } ,
1070+ serviceProvider
1071+ ) ;
1072+
1073+ await keyMongo . connect ( ) ;
1074+ instanceState . mongos . push ( keyMongo ) ;
1075+
1076+ const keyVault = await keyMongo . getKeyVault ( ) ;
1077+
1078+ const dataKey1 = await keyVault . createKey ( 'local' ) ;
1079+ const dataKey2 = await keyVault . createKey ( 'local' ) ;
1080+
1081+ const schemaMap = {
1082+ [ `${ dbname } .coll1` ] : {
1083+ bsonType : 'object' ,
1084+ properties : {
1085+ phoneNumber : {
1086+ encrypt : {
1087+ bsonType : 'string' ,
1088+ keyId : [ dataKey1 ] ,
1089+ algorithm : 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' ,
1090+ } ,
1091+ } ,
1092+ key : {
1093+ bsonType : 'string' ,
1094+ } ,
1095+ } ,
1096+ } ,
1097+ [ `${ dbname } .coll2` ] : {
1098+ bsonType : 'object' ,
1099+ properties : {
1100+ phoneNumber : {
1101+ encrypt : {
1102+ bsonType : 'string' ,
1103+ keyId : [ dataKey2 ] ,
1104+ algorithm : 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' ,
1105+ } ,
1106+ } ,
1107+ key : {
1108+ bsonType : 'string' ,
1109+ } ,
1110+ } ,
1111+ } ,
1112+ } ;
1113+
1114+ const autoMongo = new Mongo ( instanceState , uri , {
1115+ keyVaultNamespace : `${ dbname } .__keyVault` ,
1116+ kmsProviders : { local : { key : 'A' . repeat ( 128 ) } } ,
1117+ schemaMap,
1118+ } ) ;
1119+
1120+ const coll1 = autoMongo . getDB ( dbname ) . getCollection ( 'coll1' ) ;
1121+ await coll1 . insertMany ( [
1122+ { phoneNumber : '123-456-7890' , key : 'foo' } ,
1123+ { phoneNumber : '123-456-7891' , key : 'bar' } ,
1124+ ] ) ;
1125+
1126+ const coll2 = autoMongo . getDB ( dbname ) . getCollection ( 'coll2' ) ;
1127+ await coll2 . insertMany ( [
1128+ { phoneNumber : '123-456-7892' , key : 'baz' } ,
1129+ { phoneNumber : '123-456-7893' , key : 'foo' } ,
1130+ ] ) ;
1131+ const result = await (
1132+ await coll1 . aggregate ( [
1133+ {
1134+ $lookup : {
1135+ from : 'coll2' ,
1136+ localField : 'key' ,
1137+ foreignField : 'key' ,
1138+ as : 'lookupMatch' ,
1139+ } ,
1140+ } ,
1141+ ] )
1142+ )
1143+ . map ( ( { key, lookupMatch } ) => ( { key, size : lookupMatch . length } ) )
1144+ . toArray ( ) ;
1145+
1146+ expect ( result ) . deep . equals ( [
1147+ { key : 'foo' , size : 1 } ,
1148+ { key : 'bar' , size : 0 } ,
1149+ ] ) ;
1150+ } ) ;
1151+
10611152 it ( 'prints a warning when creating the keyAltNames index fails' , async function ( ) {
10621153 const mongo = new Mongo (
10631154 instanceState ,
0 commit comments