Skip to content

Modify operations

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

Use the Aerospike Go client to change entries in a map bin on the server. Increment or decrement a number, remove by key or value, or clear the map. Each operation runs through Operate(), so you don’t read and rewrite the map in your application. Increment and decrement are atomic.

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"),
)

Next steps