-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Database Trigger Options #611
Changes from 15 commits
c3fdc3b
584d75f
fe5d96b
e3c565a
985f758
7654e99
f194b81
c1de63f
ac536fc
b4a1d27
80dc42a
29969a3
90edce6
54b8333
4e1d7b5
21dea41
02f7a1b
124e590
545c72a
4961239
254fb2b
aa52585
14f6370
785e508
b76041b
449a077
740c26d
6d519eb
e6653e0
eecdaf4
239d746
a0b53cc
00b7d91
e7fcc05
a04195e
4366c18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ Database Triggers | |
:depth: 2 | ||
:class: singlecol | ||
|
||
Database Triggers allow you to execute server-side logic whenever a | ||
document is added, updated, or removed in a linked MongoDB Atlas cluster. | ||
Database Triggers allow you to execute server-side logic whenever a database | ||
change occurs on a linked MongoDB Atlas cluster. You can configure triggers on | ||
individual collections, entire databases, and on an entire cluster. | ||
|
||
Unlike SQL data triggers, which run on the database server, triggers run | ||
on a serverless compute layer that scales independently of the database | ||
server. Triggers automatically call :ref:`Atlas Functions <functions>` | ||
|
@@ -30,18 +32,6 @@ single change stream for each collection with at least one enabled | |
trigger. If multiple triggers are enabled for a collection they all | ||
share the same change stream. | ||
|
||
You control which operations cause a trigger to fire as well as what | ||
happens when it does. For example, you can run a function whenever a | ||
specific field of a document is updated. The function can access the | ||
entire change event, so you always know what changed. You can also pass | ||
the change event to :ref:`AWS EventBridge <aws-eventbridge>` to handle | ||
the event outside of Atlas. | ||
|
||
Triggers support :manual:`$match | ||
</reference/operator/aggregation/match>` expressions to filter change | ||
events and :manual:`$project </reference/operator/aggregation/project>` | ||
expressions to limit the data included in each event. | ||
|
||
.. important:: Change Stream Limitations | ||
|
||
There are limits on the total number of change streams you can open | ||
|
@@ -53,6 +43,27 @@ expressions to limit the data included in each event. | |
<serverless-caveats>` or :ref:`{+adf-instance+} | ||
<data-federation-caveats>` because they do not support change streams. | ||
|
||
You control which operations cause a trigger to fire as well as what | ||
happens when it does. For example, you can run a function whenever a | ||
specific field of a document is updated. The function can access the | ||
entire change event, so you always know what changed. You can also pass | ||
the change event to :ref:`AWS EventBridge <aws-eventbridge>` to handle | ||
the event outside of Atlas. | ||
|
||
Triggers support :manual:`$match </reference/operator/aggregation/match>` | ||
expressions to filter change events and :manual:`$project </reference/operator/aggregation/project>` | ||
expressions to limit the data included in each event. | ||
|
||
.. _trigger-recursion: | ||
|
||
.. warning:: | ||
|
||
It is possible to configure triggers that cause other triggers to fire on the | ||
same collection, database, or cluster, resulting in recursion. Examples | ||
include a database trigger writing to a collection within the same | ||
database, or a cluster-level logger writing database logs to another database | ||
in the same cluster. | ||
|
||
.. _create-a-database-trigger: | ||
|
||
Create a Database Trigger | ||
|
@@ -104,6 +115,9 @@ Configuration | |
|
||
Database Triggers have the following configuration options: | ||
|
||
Trigger Details | ||
~~~~~~~~~~~~~~~ | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 15 30 | ||
|
@@ -137,81 +151,144 @@ Database Triggers have the following configuration options: | |
|
||
.. include:: /includes/trigger-event-ordering.rst | ||
|
||
Within the :guilabel:`Trigger Source Details` section, the following configuration | ||
options are available: | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 15 30 | ||
|
||
* - Field | ||
- Description | ||
|
||
* - :guilabel:`Cluster Name` | ||
|
||
- The name of the MongoDB Service that the Trigger is | ||
associated with. | ||
|
||
* - :guilabel:`Database Name` | ||
Trigger Source Details | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
- The MongoDB database that contains the watched | ||
collection. | ||
Within the :guilabel:`Trigger Source Details` section, you first select the | ||
:guilabel:`Source Type`, based on the level of granularity you want. Your | ||
options are: | ||
|
||
* - :guilabel:`Collection Name` | ||
- :guilabel:`Collection`, when a change occurs on a specified collection | ||
- :guilabel:`Database`, when a change occurs on any collection in a | ||
specified database | ||
- :guilabel:`Deployment`, when deployment changes occur on a specified | ||
cluster. If you select the Deployment source type, the following | ||
databases are **not watched** for changes: | ||
|
||
- The name of the collection that the Trigger watches for | ||
change events. | ||
|
||
* - :guilabel:`Operation Type` | ||
- The admin databases ``admin``, ``local``, and ``config`` | ||
- The sync databases ``__realm_sync`` and ``__realm_sync_<app_id>`` | ||
|
||
Depending on which source type you are using, the additional options differ. The | ||
following table describes these options. | ||
|
||
- Checkboxes of :ref:`database operation types <database-event-operation-types>` | ||
that cause the Trigger to fire. Select the operation types you want the | ||
trigger to respond to. | ||
.. list-table:: | ||
:header-rows: 1 | ||
:widths: 15 30 | ||
|
||
.. warning:: | ||
* - Source Type | ||
- Options | ||
|
||
Update operations executed from MongoDB Compass or the MongoDB Atlas | ||
Data Explorer fully replace the previous document. As a result, | ||
update operations from these clients will generate **Replace** | ||
change events rather than **Update** events. | ||
* - :guilabel:`Collection` | ||
- | | ||
|
||
* - :guilabel:`Full Document` | ||
- :guilabel:`Cluster Name`. The name of the MongoDB cluster that the | ||
Trigger is associated with. | ||
|
||
- :guilabel:`Database Name`. The MongoDB database that contains the watched | ||
collection. | ||
|
||
- If enabled, **Update** change events include the latest | ||
:manual:`majority-committed </reference/read-concern-majority/>` | ||
version of the modified document *after* the change was applied in | ||
the ``fullDocument`` field. | ||
- :guilabel:`Collection Name`. The MongoDB collection to watch. | ||
|
||
.. note:: | ||
- :guilabel:`Operation Type`. The collection operation types | ||
that cause the Trigger to fire. Select the operation types you want the | ||
trigger to respond to. Options include: | ||
|
||
- Create Collection | ||
- Modify Collection | ||
- Rename Collection | ||
- Shard Collection | ||
- Drop Collection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in our chat, these are actually Database+ change event types. |
||
|
||
.. note:: | ||
|
||
Update operations executed from MongoDB Compass or the MongoDB Atlas | ||
Data Explorer fully replace the previous document. As a result, | ||
update operations from these clients will generate **Replace** | ||
change events rather than **Update** events. | ||
|
||
- :guilabel:`Full Document`. If enabled, **Update** change events include | ||
the latest :manual:`majority-committed </reference/read-concern-majority/>` | ||
version of the modified document *after* the change was applied in | ||
the ``fullDocument`` field. | ||
|
||
.. note:: | ||
|
||
Regardless of this setting, **Insert** and **Replace** events always | ||
include the ``fullDocument`` field. **Delete** events never include | ||
the ``fullDocument`` field. | ||
|
||
- :guilabel:`Document Preimage`. Disabled for Collection and Database | ||
sources to limit unnecessary watches on the cluster for a new | ||
collection being created. | ||
|
||
Regardless of this setting: | ||
|
||
- **Insert** and **Replace** events always include the | ||
``fullDocument`` field. | ||
|
||
- **Delete** events never include the ``fullDocument`` field. | ||
* - :guilabel:`Database` | ||
- | | ||
|
||
* - :guilabel:`Document Preimage` | ||
- :guilabel:`Cluster Name`. The name of the MongoDB cluster that the | ||
Trigger is associated with. | ||
|
||
- :guilabel:`Database Name`. The MongoDB database to watch. | ||
|
||
- :guilabel:`Operation Type`. The :ref:`database operation types | ||
<database-event-operation-types>` that cause the Trigger to fire. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Q] Only this Database row has a link, do we want to have a link for |
||
Select the operation types you want the trigger to respond to. | ||
Options include: | ||
|
||
- Create Collection | ||
- Modify Collection | ||
- Rename Collection | ||
- Shard Collection | ||
- Drop Collection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing the 2 new sharding types |
||
|
||
.. note:: | ||
|
||
Update operations executed from MongoDB Compass or the MongoDB Atlas | ||
Data Explorer fully replace the previous document. As a result, | ||
update operations from these clients will generate **Replace** | ||
change events rather than **Update** events. | ||
|
||
- :guilabel:`Full Document`. If enabled, **Update** change events include | ||
the latest :manual:`majority-committed </reference/read-concern-majority/>` | ||
version of the modified document *after* the change was applied in | ||
the ``fullDocument`` field. | ||
|
||
.. note:: | ||
|
||
Regardless of this setting, **Insert** and **Replace** events always | ||
include the ``fullDocument`` field. **Delete** events never include | ||
the ``fullDocument`` field. | ||
|
||
- :guilabel:`Document Preimage`. Disabled for Collection and Database | ||
sources to limit unnecessary watches on the cluster for a new | ||
collection being created. | ||
|
||
- If enabled, change events include a copy of the modified document | ||
from immediately *before* the change was applied in the | ||
``fullDocumentBeforeChange`` field. All change events except for | ||
**Insert** events include the document preimage. Document preimages are | ||
supported on non-sharded Atlas clusters running MongoDB 4.4+, and | ||
on sharded Atlas clusters running MongoDB 5.3 and later. | ||
* - :guilabel:`Deployment` | ||
- | | ||
|
||
.. tip:: Performance Optimization | ||
- :guilabel:`Cluster Name`. The name of the MongoDB cluster that the | ||
Trigger is associated with. | ||
|
||
- :guilabel:`Operation Type`. The operation types | ||
that occur in the cluster that cause the Trigger to fire. Select the | ||
operation types you want the trigger to respond to. Options include: | ||
|
||
- Drop Database | ||
- Create Collection | ||
- Modify Collection | ||
- Rename Collection | ||
- Shard Collection | ||
- Drop Collection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only [Q] Also do we want to add this list to each of them (COLLECTION, DATABASE, DEPLOYMENT)? |
||
|
||
Preimages require additional storage overhead that may affect | ||
performance. If you're not using preimages on a collection, | ||
you should disable preimages. To learn more, see :ref:`Disable | ||
Collection-Level Preimages | ||
<database-triggers-disable-collection-level-preimages>`. | ||
Function | ||
~~~~~~~~ | ||
|
||
Within the :guilabel:`Function` section, you choose what action is taken when | ||
the trigger fires. You can choose to run a :ref:`function <functions>` or use | ||
:ref:`AWS EventBridge <aws-eventbridge>`. | ||
|
||
Advanced | ||
~~~~~~~~ | ||
|
||
Within the :guilabel:`Advanced` section, the following **optional** configuration | ||
options are available: | ||
|
||
|
@@ -287,7 +364,6 @@ following operation types: | |
* - **Replace** | ||
- Represents a new document that replaced a document in the collection. | ||
|
||
|
||
Database change event objects have the following general form: | ||
|
||
.. code-block:: json | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may want to explicitly call out log forwarders as well here. Since, they are a first class resource that our users may also be using that could cause this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that just a specific case of a process writing to a monitored database and/or collection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, but just wanted to make customer's slightly more conscious if they didn't make that connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked offline in the project channel with team and Laura, we would like to go with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MongoCaleb Could we get an update on this since it should be going in tomorrow.