@@ -553,3 +553,97 @@ see the :ref:`Encryption algorithms <csfle-reference-encryption-algorithms>` pag
553
553
554
554
To learn more about {+csfle-abbrev+}-specific ``MongoClient`` options,
555
555
see the :ref:`mongo client <csfle-reference-mongo-client>` page.
556
+
557
+ .. _field-level-encryption-auto-encrypt-with-pattern-properties:
558
+
559
+ Encryption Schema - Encrypt with Pattern Properties
560
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
561
+
562
+ You can use the ``patternProperties`` keyword in your encryption schema to
563
+ define encryption rules for all fields with names that match a regular expression.
564
+
565
+ Consider a collection ``MedCo.patients`` where each document has
566
+ the following structure:
567
+
568
+ .. code-block:: none
569
+
570
+ {
571
+ "fname" : "<string>",
572
+ "lname" : "<string>",
573
+ "passportId_PIIString" : "<string>",
574
+ "bloodType_PIIString" : "<string>",
575
+ "medicalRecords_PIIArray" : [
576
+ {<object>}
577
+ ],
578
+ "insurance" : {
579
+ "policyNumber_PIINumber" : "<number>",
580
+ "provider_PIIString" : "<string>"
581
+ }
582
+ }
583
+
584
+ The fields that contain private data are identified by a "_PII<type>"
585
+ tag appended the end of the field name.
586
+
587
+ - ``passportId_PIIString``
588
+ - ``bloodType_PIIString``
589
+ - ``medicalRecords_PIIArray``
590
+ - ``insurance.policyNumber_PIINumber``
591
+ - ``insurance.provider_PIIString``
592
+
593
+ You can use the ``patternProperties`` keyword to configure these fields for
594
+ encryption, without identifying each field individually, and without using the
595
+ full field name. Do this by using regular expressions that match all fields that
596
+ end with the "_PII<type>" tag.
597
+
598
+ The following JSON schema uses ``patternProperties`` and regular expressions to
599
+ specify which fields to encrypt.
600
+
601
+ .. code-block:: json
602
+
603
+ {
604
+ "MedCo.patients": {
605
+ "bsonType": "object",
606
+ "patternProperties": {
607
+ "_PIIString$": {
608
+ "encrypt": {
609
+ "keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
610
+ "bsonType": "string",
611
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
612
+ },
613
+ },
614
+ "_PIIArray$": {
615
+ "encrypt": {
616
+ "keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
617
+ "bsonType": "array",
618
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random",
619
+ },
620
+ },
621
+ "insurance": {
622
+ "bsonType": "object",
623
+ "patternProperties": {
624
+ "_PIINumber$": {
625
+ "encrypt": {
626
+ "keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
627
+ "bsonType": "int",
628
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
629
+ },
630
+ },
631
+ "_PIIString$": {
632
+ "encrypt": {
633
+ "keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
634
+ "bsonType": "string",
635
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
636
+ },
637
+ },
638
+ },
639
+ },
640
+ },
641
+ },
642
+ }
643
+
644
+ The above automatic encryption rules mark the ``passportId_PIIString``,
645
+ ``bloodType_PIIString``, ``medicalRecords_PIIArray``, ``insurance.policyNumber_PIINumber``,
646
+ ``insurance.provider_PIIString`` fields for encryption.
647
+
648
+ To Learn more about the ``patternProperties`` keyword, see
649
+ :ref:`csfle-fundamentals-pattern-properties`.
0 commit comments