This topic describes how to create an ApsaraDB for MongoDB result table by using data definition language (DDL) statements in Realtime Compute and the related parameters in the WITH clause.

Note
  • This topic only applies to Realtime Compute V3.2.2 and later.
  • You cannot update the primary key in an ApsaraDB for MongoDB result table. As a result, data is inserted repeatedly into the table.

DDL syntax

In Realtime Compute, you can use ApsaraDB for MongoDB to store output data. The sample code is as follows:
CREATE TABLE mongodb_sink (
  `a`             VARCHAR
) WITH (
   type = 'mongodb'
    ,database = '<yourDatabaseName>'
    ,collection= '<yourCollectionName>'
    ,uri='mongodb://{<databaseAccount>}:{<atabasePassword>}@{host}:****? replicaSet=mgset-1224****'
    ,keepAlive='true'
    ,maxConnectionIdleTime='20000'
    ,batchSize='2000'
);

Parameters in the WITH clause

Parameter Description Required Remarks
type The type of a connector. Yes Set the value to mongodb.
database The name of an ApsaraDB for MongoDB database. Yes None.
collection A set of result table data. Yes None.
uri The URI of an ApsaraDB for MongoDB database. Yes None.
keepAlive Specifies whether a persistent connection is maintained. No Default value: true.
maxConnectionIdleTime The connection timeout duration. No An integer value. Unit: milliseconds. If this parameter is set to 0, the connection never times out. This parameter cannot be set to a negative value. Default value: 60000.
batchSize The number of data records that can be written at a time. No An integer value. Default value: 1024. The system sets the maximum number of data records that can be stored in the buffer. When the number of data records reaches the specified value of batchSize, the system triggers data output.
Note When the checkpoint time arrives, data output is triggered even if the number of data records in the buffer does not reach the specified value of batchSize.