How to update the value of a record using PK value

aql
index
query

#1

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


#2
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


#4

Thank you :grinning: @pgupta


#5

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:


#6

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