Skip to content

Modify operations

MapIncrementOp / MapDecrementOp: increment/decrement values

Atomically increments or decrements a numeric value in a map.

// Increment a counter
_, err := client.Operate(nil, key,
as.MapIncrementOp(as.DefaultMapPolicy(), "counters", "views", 1),
)
// Decrement inventory
_, err := client.Operate(nil, key,
as.MapDecrementOp(as.DefaultMapPolicy(), "inventory", "item123", 5),
)
MapRemoveByKeyOp: remove by key

Removes a key-value pair from the map.

// Remove a key
_, err := client.Operate(nil, key,
as.MapRemoveByKeyOp("profile", "oldField", as.MapReturnType.NONE),
)
// Remove and get the removed value
record, err := client.Operate(nil, key,
as.MapRemoveByKeyOp("profile", "tempData", as.MapReturnType.VALUE),
)
removedValue := record.Bins["profile"].(string) // Value that was removed
MapRemoveByValueOp: remove by value

Removes all key-value pairs that have a specific value.

// Remove all items with value "inactive"
_, err := client.Operate(nil, key,
as.MapRemoveByValueOp("status", "inactive", as.MapReturnType.KEY),
)
MapClearOp: clear all items

Removes all items from the map.

// Clear entire map
_, err := client.Operate(nil, key,
as.MapClearOp("profile"),
)
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?