Reputation: 549
I have an existing collection in ArangoDB. However there is a typo in one the document Keys.
Is it possible to rename a given Key in all documents in Arangodb ?
Upvotes: 0
Views: 1093
Reputation: 1820
To change the actual attribute name you can use some similar to the following AQL:
FOR t IN test1
//FILTER t._key == '299' //optional filter
UPDATE t WITH {
potato: t.Potatoe,
Potatoe: null
}
IN test1
OPTIONS { keepNull: false }
In the AQL above, we add a new attribute (potato), set the value to the value of the original attribute (Potatoe) and then set the original attribute to null. Finally, we use the keepNull option to tell the system to remove the Potatoe attribute.
Note that the AQL above will only remove the nulls that are the result of the statement. So if you have a 'rice' attribute in your table that is already null, the system will not delete it since 'rice' is not part of the update statement.
Upvotes: 2
Reputation:
If it is a systematic aberation, use an AQL-Update statement, e.g.:
FOR c IN collection
FILTER c.pointer == OFFENDING_KEY
LET newC = {pointer: CORRECT_KEY}
UPDATE c WITH newC IN collection OPTIONS {exclusive: true}
Upvotes: 0