func DBUpdateAuctionItem(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userId string, info *AuctionItem, auctionItemId string, version string) error {
// Write the updated items to storage
infoJson, err := json.Marshal(info)
if err != nil {
logger.Error("error marshaling AuctionItem")
return runtime.NewError("error marshaling items", int(codes.Internal))
}
writeRequest := &runtime.StorageWrite{
Collection: STORAGE_AUCTION_COLLECTION_NAME,
Key: auctionItemId,
UserID: userId,
PermissionRead: 1,
PermissionWrite: 1,
Value: string(infoJson),
Version: version,
}
logger.Info("DBUpdateAuctionItem writeRequest:%v,version:%v", *writeRequest, writeRequest.Version)
// Return an error if the write does not succeed
storageWriteAck, err := nk.StorageWrite(ctx, []*runtime.StorageWrite{writeRequest})
if err != nil || len(storageWriteAck) == 0 {
logger.Error("error saving items", err)
return runtime.NewError("error saving items", int(codes.Internal))
}
logger.Info("DBUpdateAuctionItem storageWriteAck", storageWriteAck)
return nil
}
and the log is
{"level":"info","ts":"2024-06-27T07:22:58.977Z","caller":"logic/rpc.go:1616","msg":"RpcBuyAuctionItem object%!(EXTRA *api.StorageObject=collection:\"auction\" key:\"714f923c-176a-44e0-ba67-0c0208a567da\" user_id:\"4f9dc684-30ad-451b-8c5c-6cbb6fa93dc7\" value:\"{\\\"EndTime\\\":1720074125,\\\"FixedPrice\\\":22,\\\"InitPrice\\\":1,\\\"Item\\\":{\\\"Char\\\":10002,\\\"ConfigId\\\":90000001,\\\"Entry\\\":{},\\\"Grade\\\":1,\\\"Id\\\":\\\"4b5840a2-f976-484d-8d8f-02022645dcd3\\\",\\\"Num\\\":1,\\\"Property\\\":{\\\"7\\\":10},\\\"Slot\\\":1},\\\"NowBuyUserId\\\":\\\"\\\",\\\"NowPrice\\\":1}\" version:\"49ee1271e2a01a41c031f071b22c2d23\" permission_read:1 permission_write:1 create_time:{seconds:1719469325 nanos:752121000} update_time:{seconds:1719469325 nanos:752121000})","runtime":"go","rpc_id":"buy_auction_item"}
{"level":"info","ts":"2024-06-27T07:22:58.977Z","caller":"logic/auction.go:110","msg":"DBUpdateAuctionItem writeRequest:{auction 714f923c-176a-44e0-ba67-0c0208a567da c3abac4a-6163-4973-8942-fcd9f6d129a9 {\"Item\":{\"Id\":\"4b5840a2-f976-484d-8d8f-02022645dcd3\",\"ConfigId\":90000001,\"Entry\":{},\"Num\":1,\"Property\":{\"7\":10},\"Slot\":1,\"Grade\":1,\"Char\":10002},\"InitPrice\":1,\"NowPrice\":5,\"NowBuyUserId\":\"c3abac4a-6163-4973-8942-fcd9f6d129a9\",\"FixedPrice\":22,\"EndTime\":1720074125,\"UserId\":\"\"} 49ee1271e2a01a41c031f071b22c2d23 1 1},version:49ee1271e2a01a41c031f071b22c2d23","runtime":"go","rpc_id":"buy_auction_item"}
{"level":"debug","ts":"2024-06-27T07:22:58.981Z","caller":"server/core_storage.go:588","msg":"Error writing storage objects.","error":"Storage write rejected - version check failed."}
database object version is also 49ee1271e2a01a41c031f071b22c2d23