Batch write operation to replace the whole record

I am using go client to create or replace 100 records at a time. In batch mode, I could not find an operation that accepts a BinMap and replaces the whole record with that BinMap. I could find only the PutOp operation that writes a single bin.

I could programmatically build a series of PutOp operations (for each bin one operation) and then invoke the NewBatchWrite, however that does not solve the requirement of “replace” the whole record. I mean, if there is already a record for this key, with some bins (which I am not updating in my batch PutOp), the result is not a complete replace of this record. ie. the record is going to have the old bins + the bins I write newly.

It would be great if we have a PutBins that accept a BinMap and replaces the whole record with this BInMap. Or is there any other way to achieve this ?

Below is the code that deals with single bin per operation.

for i := 0; i < len(recs); i++ {
        ops := make([]*aerospike.Operation, len(recs[i].bins))
		for binNum, bin := range recs[i].bins {
			ops[binNum] = aerospike.PutOp(bin)
		}
		aeroBatch = append(aeroBatch, aerospike.NewBatchWrite(nil, recs[i].key, ops...))
}
err := cli.BatchOperate(nil, aeroBatch)
...

Both capabilities that you are looking for are supported. It is possible to 1) replace an existing record, and 2) perform multiple bin writes in one batch operation.

For 1, you should specify RecordExistsAction = REPLACE in NewBatchWrite’s BatchWritePolicy parameter. For 2, you can add multiple bin write operations in the NewBatchWrite’s ops parameter (although the syntax with BinMap is not available). Hope this answers your question. (I have not tried this in Go, but think it should work based on my understanding of the Java client.)

thanks @neelp I was building the ops for each bin, and supplying to the NewBatchWrite. I will continue with that approach.

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