Multiple ops on same bin of a record

Hi,

Is there a way to submit multiple operations on the same bin of a record and return two different values?

For e.g., let us say I have a set academics with a Map field students that stores score => studentId mapping.

{score: studentId}

Let us say, I want to query for the size of this map as well as the studentId with the topmost score, I’d do this the following way in Python:

import aerospike
from aerospike_helpers.operations import map_operations as mapops
from aerospike_helpers.operations import operations as op_helpers

# Configure the client
config = {
 'hosts': [ ('127.0.0.1', 3000) ]
}

# Create a client and connect it to the cluster
try:
  client = aerospike.client(config).connect()
except:
  import sys
  print("failed to connect to the cluster with", config['hosts'])
  sys.exit(1)

key = ('ns', 'academics', 'physics')
ops = []
op = mapops.map_size("students")
ops.append(op)

op = mapops.get_by_rank("students", -1, aerospike.MAP_RETURN_VALUE)
ops.append(op)

_, _, bins = client.operate(key, ops)
print(bins)

Unfortunately the output of the 2nd op overwrites the output of the 1st op. Is there a way to achieve this?

Thanks.

Per the API documentation for operate() states that “the returned record tuple will only contain one element per bin, even if multiple operations were performed on the bin”. Please try operate_ordered() to get multiple values for a bin.

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