Insert Items in NoSQL Tables

Catalyst enables you to insert items in a specific NoSQL table after you construct them. The items can be inserted in different ways as described in this section.

You can refer to the help sections on adding and working with data, the Catalyst custom JSON format, and the supported data types to learn these topics in detail.

Note: Catalyst enables you to insert a maximum of 25 items in bulk in a NoSQL table with a single SDK operation.

Insert Items without Conditions

You can insert new items into a NoSQL table without any conditions by constructing the items in the Catalyst custom JSON format. This will require you to mandatorily pass the values for the partition key and sort key attributes configured for the table.

For example, in the code snippet below, the values for the partition key and sort key attributes of the item, fruitName and Location respectively, are provided. Other attributes of the string data type such as fruitType and availability are provided as a list fruitProperties. The item is then inserted using the insert_items() method.

    
copy
# Insert a NoSQL item without conditions item = { "fruitName": { "S": "Banana" }, "Location": { "S": "Indonesia" }, "fruitProperties": { "L": [ { "fruitType": "Berries" }, { "availability": "abundant" } } ] } } # Insert the item based on the defined condition and set the item to be returned in the response. Other supported values are "OLD" and "NULL" res = table.insert_items({ 'item': item, 'return': 'NEW' })

Insert Items with Conditional Functions

You can insert attributes in existing items in a NoSQL table using specific conditions that you define in the Catalyst custom JSON format. In this type, the existing data of the table is retrieved and evaluated against the specified condition. The items are inserted only if the evaluation is true. If there is no existing data, the conditions are ignored and the items are inserted.

Catalyst supports multiple operators to evaluate conditions. The supported operators are represented as shown below.

Operators Notation
CONTAINS contains
NOT_CONTAINS not_contains
BEGINS_WITH begins_with
ENDS_WITH ends_with
IN in
NOT_IN not_in
BETWEEN between
NOT_BETWEEN not_between
EQUALS equals
NOT_EQUALS not_equals
GREATER_THAN greater_than
LESS_THAN less_than
GREATER_THAN_OR_EQUALS greater_equal
LESSER_THAN_OR_EQUALS less_equal
AND AND
OR OR

The example below illustrates this by defining a condition for the nested attribute fruitColour in the existing data to contain the value “Yellow”. This attribute is part of the attribute fruitProperties. If the condition is satisfied, the attributes fruitType and availability are added to the items. The item is then inserted using the insert_items() method.

    
copy
# Insert a NoSQL item with a conditional function condition_function = { "function": { "function_name": "attribute_type", "args": [ { "attribute_path": ["fruitProperties", "[0]"] }, { "fruitColour": "Yellow" } ] } } item = { "Location": { "S": "Indonesia" }, "fruitName": { "S": "Banana" }, "fruitProperties": { "L": [ { "fruitType": "Berries" }, { "availability": "abundant" } } ] } } # Insert the item based on the defined condition and set the return value in the response. Other supported values are "OLD" and "NULL" res = table.insert_items({ 'item': item, 'condition': condition_function, 'return': 'NEW' })

Insert Items with Conditional Operators

Catalyst also enables you to insert items based on conditions defined with operators in the Catalyst custom JSON format. The existing data of the table is retrieved and evaluated against the specified condition. The items are inserted only if the evaluation is true. If there is no existing data, the conditions are ignored and the items are inserted.

Catalyst supports multiple operators to evaluate conditions, as listed in the previous section.

The example below illustrates inserting an item based on conditions defined with the between operator. The condition states that only when the attribute count has values between 0 and 10 in the existing data, the attributes backupID and count are to be inserted in those items. The item is inserted with the insert_items() method.

    
copy
# Insert a NoSQL item with a conditional operator condition_function = { "attribute": ["count"], "operator": "between", "value": { "L": [ { "N": "0" }, { "N": "10" } ] } } item = { "countryCode": { "N": 054 }, "backupID": { "N": 2379992 }, "count": { "N": "3" } } # Insert the item based on the defined condition and set the return value in the response. Other supported values are "OLD" and "NULL" res = table.insert_items({ 'item': item, 'condition': condition_function, 'return': 'NEW' })

Last Updated 2025-06-20 16:21:48 +0530 +0530