Map operations
For the complete documentation index see: llms.txt
All documentation pages available in markdown.
Use nested map operations in the Aerospike Go client to store a multi-level map in a bin and read or write a value deep inside it. Pass a Collection Data Type (CDT) context, such as CtxMapKey, to an operation to point it at the nested map, so the server does the work and your application doesn’t read and rewrite the whole structure.
Example: user with nested address map
// Store nested structureuserData := map[any]any{ "name": "John Doe", "address": map[string]any{ "street": "123 Main St", "city": "San Francisco", "zip": "94102", },}
key, _ := as.NewKey("app", "users", "user123")_, err := client.Operate(nil, key, as.MapPutItemsOp(as.DefaultMapPolicy(), "user", userData),)
// Get nested cityctx := []*as.CDTContext{ as.CtxMapKey(as.StringValue("address")),}
record, err := client.Operate(nil, key, as.MapGetByKeyOp("user", "city", as.MapReturnType.VALUE, ctx...),)
results := record.Bins["user"].(map[any]any)city := results["city"].(string)fmt.Println("City:", city) // Output: City: San FranciscoExample: multi-level configuration
// Store nested configurationconfig := map[any]any{ "database": map[string]any{ "primary": map[string]any{ "host": "db1.example.com", "port": 3306, }, "replica": map[string]any{ "host": "db2.example.com", "port": 3306, }, },}
key, _ := as.NewKey("app", "config", "production")_, err := client.Operate(nil, key, as.MapPutItemsOp(as.DefaultMapPolicy(), "config", config),)
// Get primary database hostctx := []*as.CDTContext{ as.CtxMapKey(as.StringValue("database")), as.CtxMapKey(as.StringValue("primary")),}
record, err := client.Operate(nil, key, as.MapGetByKeyOp("config", "host", as.MapReturnType.VALUE, ctx...),)
host := record.Bins["config"].(string)fmt.Println("Primary DB host:", host)Next steps
- Nested CDT operations: how CDT contexts navigate nested maps and lists
- Nested list operations
- Map get operations
- Quick reference