ArangoDB是一個多模型數據庫,它使用AQL(ArangoDB查詢語言)作為查詢和操作數據的語言。為了簡化代碼,你可以遵循以下建議:
const name = "John";
const query = `FOR user IN users FILTER user.name == @name RETURN user`;
db.query(query, { name: name });
const query = `FOR document IN myCollection COLLECT value = SUM(document.value) RETURN { total: value }`;
db.query(query);
const transaction = `
FOR user IN users
UPDATE { name: user.name, age: user.age + 1 } IN users
`;
db.executeTransaction(
{
write: ["users"],
},
transaction
);
const query = `
FOR v, e IN 1..1 OUTBOUND "users/myUser" GRAPH "myGraph"
RETURN v, e
`;
db.query(query);
CREATE PROCEDURE updateUserAge() {
LET user = DOCUMENT("users/myUser");
UPDATE user WITH { age: user.age + 1 } IN users;
RETURN user;
}
通過遵循這些建議,你可以簡化ArangoDB查詢語言代碼,使其更易讀、高效且易于維護。