last night i had some sort of break through - after comparing the operations line by line i realised the java code does a operate() while the go does a putBins(). the main difference is the operate accepts a MapPolicy parameter while go code doesnt have it.
if i add something like:
MapPolicy mapObsBinPolicy = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteFlags.DEFAULT);
Record changeOrder =
client.operate(null, key, MapOperation.setMapPolicy(mapObsBinPolicy, mapObsBinName))```
(java code found online - ive added the equivalent in go)
then it seems to work both ways however i am not sure how i could merge the put bins and set map policy in a single call… i will make sure to update if i ever work it out.
You could accomplish that in a single call using the client.Operate method.
Using the example from Meher above, if you wanted to store as a key ordered map:
import (
"fmt"
"github.com/aerospike/aerospike-client-go/v6"
)
// Establishes a connection to the server
client, err := aerospike.NewClient("127.0.0.1", 3000)
// Create the record key
key, err := aerospike.NewKey("sandbox", "ufodata", 5001)
// Create the bin
report := aerospike.NewBin("report", map[string]interface{}{
"city": "Ann Arbor",
"state": "Michigan",
"shape": []string{"circle", "flash", "disc"},
"duration": "5 minutes",
"summary": "Large flying disc flashed in the sky above the student union. Craziest thing I've ever seen!"})
// Create the map policy
mapPolicy := aerospike.NewMapPolicyWithFlags(aerospike.MapOrder.KEY_ORDERED, aerospike.MapWriteFlagsDefault)
// Write the record
record, err := client.Operate(nil, key,
aerospike.PutOp(report),
aerospike.MapSetPolicyOp(mapPolicy, "report"))
// Close the connection to the server
client.Close()
That should write the record, then apply the policy. You can test it out in the sandbox, just copy and paste the code sample and run it, then run from the aql prompt in the terminal: