Help Center> FunctionGraph> User Guide> Getting Started> Using a GaussDB(for Mongo) Trigger

Using a GaussDB(for Mongo) Trigger

This section describes how to create a GaussDB(for Mongo) trigger for a function.

A function using a GaussDB(for Mongo) trigger will be triggered every time a database table is updated. For details about the GaussDB(for Mongo) event source, see Supported Event Sources.

Currently, GaussDB(for Mongo) triggers are supported only in the following regions: CN North-Beijing4, CN North-Ulanqab201, CN East-Shanghai1, CN South-Guangzhou, CN-Hong Kong, and AP-Singapore.

Prerequisites

Before creating a GaussDB(for Mongo) trigger, make sure you have prepared the following:

Creating a GaussDB(for Mongo) Trigger

  1. Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
  2. Click the HelloWorld function.
  3. On the function details page that is displayed, click the Triggers tab.
  4. Click Create Trigger.
  5. Set the following parameters:

    • Trigger Type: Select GaussDB(for Mongo).
    • GaussDB(for Mongo) Instance: Select a GaussDB(for Mongo) instance.
    • Password: Enter the password of the GaussDB(for Mongo) instance administrator rwuser.
    • Database: Enter the name of a GaussDB(for Mongo) database. Note that admin, local, and config are reserved database names and cannot be used here.
    • Collection: Enter the name of a database collection.
    • Batch Size: Set the number of records to be read from the database at a time.

  6. Click OK.

Configuring a GaussDB(for Mongo) Event to Trigger the Function

  1. Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
  2. Click the HelloWorld function.
  3. On the displayed function details page, select a version and choose Select test event > Configure test event.
  4. Set the parameters described in Table 1 and click Save.

    Table 1 Test event information

    Parameter

    Description

    Configure Test Event

    You can create a test event or edit an existing one.

    Use the default option Create new test event.

    Event Template

    Select gaussmongo-event-template.

    Event Name

    The event name can contain 1 to 25 characters and must start with a letter and end with a letter or digit. Only letters, digits, underscores (_), and hyphens (-) are allowed. For example, gaussmongo-123test.

    Event data

    The system automatically loads the built-in GaussDB(for Mongo) event template, which is used in this example without modifications.

    The event template is as follows:

    {
    	"records": [{
    		"event_name": "\"insert\"",
    		"event_version": "1.0",
    		"event_source": "gauss_mongo",
    		"region": "cn-north-1",
    		"gauss_mongo": {
    			"full_document": "{\"_id\": {\"$oid\":\"5f61de944778db5fcded3f87\"},\"zhangsan\": \"zhangsan\"}",
    			"ns": "{\"db\": \"zhangsan\",\"coll\": \"zhangsan\"}",
    			"size_bytes": "100",
    			"token": "{\"_data\": \"825F61DE940000000129295A1004A2D9AE61206C43A5AF47CAF7C5C00C5946645F696400645F61DE944778DB5FCDED3F870004\"}"
    		},
    		"event_source_id": "51153d19-2b7d-402c-9a79-757163258a36"
    	}],
    	"vernier": "{\"_data\": \"825F61DE940000000129295A1004A2D9AE61206C43A5AF47CAF7C5C00C5946645F696400645F61DE944778DB5FCDED3F870004\"}"
    }

  5. Click Test. The function test result is displayed. Figure 1 shows the details.

    Figure 1 Test result of the GaussDB(for Mongo) trigger