I have a graph DB and the requirement is to update an attribute in a few vertices. Now let's assume I have to update an attribute value from 0 to 1.
Approach #1 - run update for each vertex in a loop
foreach(int id in ids) {
g.V().has('vertex','key','test').has('id', id).Property('status','1')
}
RU utilized per query -
METRIC | VALUE
Request Charge | 17.29
Approach #2 - use a single Gremlin Query to update all vertex
g
.V()
.has('vertex','key','test')
.has('id', within('1','2','3'))
.Property('status','1')
METRIC | VALUE
Request Charge | 41.4
Which approach is better considering the RUs and time taken to run the code?
You should use the query that consumes least amount of RUs, like @Mark Brown suggested. However, keep in mind that there will be gremlin query length limitations enforced by your client as well as by cosmos. cosmosDB gremlin API requires your query length to be less than 2^16 = 65536
. You may have to batch your request depending on the size of your ids