You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OrientDB批量更新后如何返回指定属性而非RecordLink?

Solution for OrientDB Batch Update Returning Name-RID Map

The issue with your current batch command is that you're returning an array of full records (represented as OrientDBRecordLink objects), which don't directly give you the key-value format you want. Instead, you need to build a map incrementally in your batch script that maps each updated name to its RID.

Here's the corrected batch command that will return the exact format you're looking for:

begin;
-- Initialize an empty map to store our name-RID pairs
let result = {};

-- First update: modify the record and capture the updated version
let a0 = update #44:845 merge {"name": "B4"} return after;
-- Add the name and RID to our result map (convert RID to string for the desired format)
let result = result.put($a0.name, $a0.@rid.toString());

-- Second update
let a1 = update #44:849 merge {"name": "Name4"} return after;
let result = result.put($a1.name, $a1.@rid.toString());

-- Repeat the above two lines for all your updates...

-- Commit the transaction with retry logic
commit retry 100;

-- Return the final map
return result;

Key Details:

  1. Initializing the Map: We start with let result = {} to create an empty dictionary that will hold our key-value pairs.
  2. Capturing Updated Records: Each update ... return after statement stores the fully updated record in a variable (like $a0). This gives us access to both the new name property and the record's @rid.
  3. Building the Map: Using result.put(key, value), we add each entry to the map. We call toString() on @rid because it's an ORecordId object by default—converting it to a string gives you the familiar #44:845 format.
  4. Commit and Return: After all updates are processed, we commit the transaction and return the completed map.

Important Notes:

  • If multiple updates set the same name value, the last one will overwrite the previous entry in the map (since map keys must be unique).
  • The merge operation ensures the name property is set (even if it didn't exist before), so you don't have to worry about missing values in the result.

内容的提问来源于stack exchange,提问作者Diemo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:40:19