Skip to content

Commit 8f27c3d

Browse files
authored
[Encryption] PHPORM-360 Document limitations of encryption with collection inheritance (#2790)
1 parent cd6f6d2 commit 8f27c3d

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

docs/en/reference/attributes-reference.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ Optional arguments:
356356
users only. The default values for these options are suitable for the majority
357357
of use cases, and should only be modified if your use case requires it.
358358

359+
.. note::
360+
361+
Queryable encryption is only supported in MongoDB version 8.0 and later.
362+
359363
Example:
360364

361365
.. code-block:: php
@@ -373,9 +377,50 @@ Example:
373377
public string $name;
374378
}
375379
380+
The ``#[Encrypt]`` attribute can be added to a class with `#[EmbeddedDocument]`_.
381+
This will encrypt the entire embedded document, in the field that contains it.
382+
Queryable encryption is not supported for embedded documents, so the ``queryType``
383+
argument is not applicable. Encrypted embedded documents are stored as a binary
384+
value in the parent document.
385+
386+
.. code-block:: php
387+
388+
<?php
389+
390+
use Doctrine\ODM\MongoDB\Mapping\Annotations\Encrypt;
391+
392+
#[Encrypt]
393+
#[EmbeddedDocument]
394+
class CreditCard
395+
{
396+
#[Field]
397+
public string $number;
398+
399+
#[Field]
400+
public string $expiryDate;
401+
}
402+
403+
#[Document]
404+
class User
405+
{
406+
#[EmbedOne(targetDocument: CreditCard::class)]
407+
public CreditCard $creditCard;
408+
}
409+
376410
For more details, refer to the MongoDB documentation on
377411
`Queryable Encryption <https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/>`_.
378412

413+
414+
.. note::
415+
416+
The encrypted collection must be created with the `Schema Manager`_ before
417+
before inserting documents.
418+
419+
.. note::
420+
421+
Due to the way the encrypted fields map is generated, the queryable encryption
422+
is not compatible with ``SINGLE_COLLECTION`` inheritance.
423+
379424
#[Field]
380425
--------
381426

@@ -1439,5 +1484,6 @@ root class specified in the view mapping.
14391484
.. _DBRef: https://docs.mongodb.com/manual/reference/database-references/#dbrefs
14401485
.. _geoNear command: https://docs.mongodb.com/manual/reference/command/geoNear/
14411486
.. _MongoDB\BSON\ObjectId: https://www.php.net/class.mongodb-bson-objectid
1487+
.. _Schema Manager: ../reference/migrating-schemas
14421488
.. |FQCN| raw:: html
14431489
<abbr title="Fully-Qualified Class Name">FQCN</abbr>

docs/en/reference/migrating-schemas.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@ problem!
1515
for the Google App Engine datastore. Additional information may be found in
1616
the `Objectify schema migration`_ documentation.
1717

18+
Creating a collection
19+
--------------------
20+
21+
Collections are automatically created by the MongoDB server upon first insertion.
22+
You must explicitly create the collections if you need specific options, such as
23+
validation rules. In particular, encrypted collections must be created explicitly.
24+
25+
.. code-block:: php
26+
27+
<?php
28+
29+
// Assuming $dm is your DocumentManager instance
30+
$schemaManager = $dm->getSchemaManager();
31+
32+
To create the collections for all the document classes, you can use the
33+
`createCollections()` method on the ``DocumentManager``:
34+
35+
.. code-block:: php
36+
37+
<?php
38+
39+
$schemaManager->createCollections();
40+
41+
For a specific document class, you can use the `createDocumentCollection()`
42+
method with the class name as an argument:
43+
44+
<?php
45+
46+
$schemaManager->createDocumentCollection(Person::class);
47+
48+
Once the collection is created, you can also set up indexes with ``ensureIndexes``,
49+
and search indexes with ``createSearchIndexes``:
50+
51+
<?php
52+
53+
$schemaManager->ensureIndexes();
54+
$schemaManager->createSearchIndexes();
55+
1856
Renaming a Field
1957
----------------
2058

0 commit comments

Comments
 (0)