How to update the value of a record using PK value

Hello

i have test namespace,demo set and some records

"email": "abc@gmail.com",
"id": 12345 ,
"date": {
     "Jun": [ "3", "4" ],
     "July": [ "12", "7" ] 
   }

i want to update only “Jun” field with using PK value or secondary index.

ex: update into test.demo date.Jun=[ "2", "31" ] where PK=1

If this is not possible with aql ,can u please provide solution in python client

import aerospike
# Open connection to the server
config = { 'hosts': [ ("localhost", 3000), ] }
client = aerospike.client(config).connect()

key = ("test", "demo", 1)
client.map_put(key, bin="date", map_key="Jun", val=["3","4"])
ret_val=client.map_get_by_key(key, bin="date", map_key='Jun', return_type=aerospike.MAP_RETURN_VALUE)
print ret_val

For other API calls available, see python client documentation. http://www.aerospike.com/apidocs/python/client.html#aerospike.Client.operate

2 Likes

Thank you :grinning: @pgupta

hello @pgupta

if i update like this

key = (“test”, “demo”, 1) client.map_put(key, bin=“date”, map_key=“Jun”, val=[“3”,“4”]) ret_val=client.map_get_by_key(key, bin=“date”, map_key=‘Jun’, return_type=aerospike.MAP_RETURN_VALUE) print ret_val

Here only one map_key value is updating, I have 100 map_keys in my records, its taking time to update one by one map_key, how to update multiple map_keys at a time?

ex:client.map_put(key, bin=“date”, map_key=“Jun”,"July val=[“3”,“4”],[“1”,“2”])

i tried this but getting arg error :frowning_face:

Use map_put_items() , see usage here: https://www.aerospike.com/apidocs/python/client.html?highlight=map_put#aerospike.Client.map_put_items

1 Like

you can update using aql as well i attached a sample data

aql> insert into test.demo (PK,"email","id","date") VALUES ( 1, "abc@gmail.com", 12345 , '{ "Jun": [ "3", "4" ], "July": [ "12", "7" ] }')
OK, 1 record affected.

aql> select * from test.demo where PK=1
+-----------------+-------+--------------------------------------------------+
| email           | id    | date                                             |
+-----------------+-------+--------------------------------------------------+
| "abc@gmail.com" | 12345 | "{ "Jun": [ "3", "4" ], "July": [ "12", "7" ] }" |
+-----------------+-------+--------------------------------------------------+
1 row in set (0.000 secs)

OK

aql> insert into test.demo (PK,"date") VALUES ( 1,'{ "Jun": [ "2", "30" ], "July": [ "12", "7" ] }')
OK, 1 record affected.

aql> select * from test.demo where PK=1
+-----------------+-------+---------------------------------------------------+
| email           | id    | date                                              |
+-----------------+-------+---------------------------------------------------+
| "abc@gmail.com" | 12345 | "{ "Jun": [ "2", "30" ], "July": [ "12", "7" ] }" |
+-----------------+-------+---------------------------------------------------+
1 row in set (0.000 secs)

OK

aql> 

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.