You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DOC-11974] Added 4 new scriptlet pages and updated Eventing Examples page (Jon's feedback in #157) (#161)
* Added Jon's new files to this new PR
* Edited existing pages to match style and format of new pages
* Added new examples to page and updated formatting and language
* Updated nav file with links to new function files
* Updated nav page order
* More updates
* Revert "More updates"
This reverts commit faa5a2a.
* Deleted nav partial from this PR as I already have the file sitting in a different PR
:description: This page contains examples of how to use the Eventing Service, using the Couchbase Web Console.
2
+
:description: This page contains examples of how to use the Eventing Service with the Couchbase Web Console.
3
3
:page-edition: Enterprise Edition
4
4
5
5
+++ <!-- Couchbase Eventing Examples --> +++
6
6
[abstract]
7
7
{description}
8
8
9
9
[#examples-step-by-step]
10
-
== Step by Step Examples
10
+
== Step-by-Step Examples
11
11
12
12
[#Couchbase-Eventing-Examples]
13
-
*Detailed Examples*: These tutorial-like guides are ideal for a novice to learn the basics of the Eventing Service, via complete detailed step by step start-to-finish instructions.
13
+
=== Detailed Examples
14
14
15
-
[cols="1,1,1"]
15
+
The following tutorial-like guides have detailed start-to-finish instructions and are ideal for new users to learn the basics of the Eventing Service.
*Basic KV Eventing Functions*: The following Scriptlets are essentially stand alone Eventing Functions examples, and introduce more use cases. Here we assume the reader has a good understanding of the Eventing System and requires little guidance.
38
+
=== Basic Accessor Eventing Functions
39
+
40
+
The following scriptlets are examples of standadlone Eventing Functions.
*Generic Manipulation Eventing Functions* The following Scriptlets are more advanced use cases which focus on mutating documents without knowledge of the document's schema.
73
+
=== Generic Manipulation Eventing Functions
64
74
65
-
[cols="1,1,1"]
75
+
The following scriptlets are examples of advanced use cases that focus on mutating a document without knowing that document's schema.
*Advanced Accessor Eventing Functions*: The following Scriptlets demonstrate using Advanced Bucket Accessors (introduced in version 6.6.1) which allow the use of CAS, ability to set expirations (or TTLs) and the use of distributed atomic counters to increment or decrement counts.
90
+
=== Advanced Accessor Eventing Functions
80
91
81
-
[cols="1,1,1"]
92
+
The following scriptlets demonstrate how to use Advanced Keyspace Accessors, which allow you to:
93
+
94
+
* Use CAS
95
+
* Set expiry (TTL) dates
96
+
* Use distributed atomic counters to increment and decrement counts
*Binary Document Support*: The following Scriptlets demonstrate support for binary documents in Eventing. Only a Function with “language compatibility” of 6.6.2 or above in its settings will pass binary documents to the OnUpdate(doc,meta) handler.
119
+
=== Binary Document Support
120
+
121
+
The following scriptlets demonstrate support for binary documents in Eventing.
122
+
123
+
Your Eventing Function must have a language compatibility setting of Couchbase Server version 6.6.2 or above to pass binary documents in its `OnUpdate(doc,meta)` handler.
Copy file name to clipboardExpand all lines: modules/eventing/pages/eventing-handler-advanced-docControlledSelfExpiry.adoc
+44-41Lines changed: 44 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,43 +1,46 @@
1
1
= Function: Advanced Document Controlled Expiry
2
-
:description: pass:q[Purge a document automatically based on self-contained start and duration fields.]
2
+
:description: pass:q[Purge a document automatically based on the document's self-contained start and duration fields.]
3
3
:page-edition: Enterprise Edition
4
4
:tabs:
5
5
6
-
*Goal*: {description}
7
-
8
-
* This function *advancedDocControlledSelfExpiry* demonstrates self-expiry of a document; for example, a user trial.
9
-
* Requires Eventing Storage (or metadata collection) and a "source" collection.
10
-
* Needs a Binding of type "bucket alias" (as documented in the Scriptlet).
11
-
* When documents are created, they will have no expiration value. This function processes the initial mutation to calculate and set the proper TTL.
12
-
* In Couchbase, when using a simple integer expiry value (as opposed to a proper date or time object), the expiration can be specified in two ways:
13
-
** As an offset from the current time. If the absolute value of the expiry is less than 30 days (60 * 60 * 24 * 30 seconds), it is considered an offset.
14
-
** As an absolute Unix time stamp. If the value is greater than 30 days (60 * 60 * 24 * 30 seconds), it is considered an absolute time stamp.
15
-
** As described in xref:learn:data/expiration.adoc[Expiration], if a "Bucket Max Time-To-Live" is set (specified in seconds), it is an enforced hard upper limit. As such, any subsequent document mutation (by {sqlpp}, Eventing, or any Couchbase SDK) will result in the document having its expiration adjusted and set to the bucket’s maximum TTL if the operation has:
16
-
*** No TTL.
17
-
*** A TTL of zero.
18
-
*** A TTL greater than the bucket TTL.
19
-
* As we are using Advanced Bucket Accessors setting document expirations (or TTLs) we use a JavaScript Data object.
20
-
* Will operate on any document with type == "trial_customers".
21
-
* Will ignore any doc with a non-zero TTL
22
-
* This is different than setting a TTL on a bucket or a collection which will typically update (or extend) the TTL of a document on each mutation.
6
+
{description}
7
+
8
+
The `advancedDocControlledSelfExpiry` function:
9
+
10
+
* Demonstrates the self-expiry of a document (for example, a user trial)
11
+
* Requires Eventing Storage (or a metadata collection) and a source collection
12
+
* Requires a binding of type `bucket alias`
13
+
* Processes the initial mutation to calculate and set the TTL of a newly-created document
14
+
* Uses a JavaScript data object to set document expiration
15
+
* Operates on any document where `type == "trial_custoimers"`
16
+
* Ignores any document with a TTL that is not zero
17
+
18
+
When you use a simple integer instead of a proper date or time object for your document's expiration value, the expiration value is specified in one of the following ways:
19
+
20
+
* As an offset from the current time if the value is less than 30 days (60 * 60 * 24 * 30 seconds).
21
+
* As an absolute Unix time stamp if the value is greater than 30 days (60 * 60 * 24 * 30 seconds).
22
+
23
+
If a `Bucket Max Time-to-Live` is set and specified in seconds, it's enforced as a hard upper limit.
24
+
Any subsequent document mutation, whether by {sqlpp}, Eventing, or a Couchbase SDK, results in the document having its expiration adjusted and set to the bucket's maximum TTL if the operation has:
25
+
26
+
* No TTL
27
+
* A TTL of zero
28
+
* A TTL greater than the bucket's TTL
23
29
24
30
[{tabs}]
25
31
====
26
32
advancedDocControlledSelfExpiry::
27
33
+
28
34
--
29
-
Two variants of this function are available - a 6.6 version that relies on {sqlpp} and a 6.6.1+/7.0.0+ version (*this Function*) that directly sets the expiration.
30
-
You can completely avoid _N1QL(...)_ and use _couchbase.replace(bucket_binding, meta, doc)_ as the advancedDocControlledSelfExpiry variant is much faster.
35
+
There are two variants of this function available: a xref:eventing-handler-docControlledSelfExpiry.adoc[Couchbase Server version 6.6 that relies on {sqlpp}], and a Couchbase Server version 6.6.1+/7.0.0+ that directly sets the expiration.
31
36
32
-
* xref:eventing-handler-docControlledSelfExpiry.adoc[docControlledSelfExpiry (indirect TTL via {sqlpp})]
We end up with two (2) of the four documents (obviously you may need to adjust the {sqlpp} INSERT in a few months as all the document would be immediately deleted).
185
+
Returns 2 of the 4 documnents.
183
186
184
187
* "trial_customers::0" was deleted
185
188
* "trial_customers::1" was deleted
@@ -188,4 +191,4 @@ We end up with two (2) of the four documents (obviously you may need to adjust t
0 commit comments