Basic Document operations
Every document operations works with POJOs (e.g. MyObject), VelocyPack (VPackSlice) and Json (String).
For the next examples we use a small object:
public class MyObject {
private String key;
private String name;
private int age;
public MyObject(String name, int age) {
this();
this.name = name;
this.age = age;
}
public MyObject() {
super();
}
/*
* + getter and setter
*/
}
insert document
MyObject myObject = new MyObject("Homer", 38);
arangoDB.db("myDatabase").collection("myCollection").insertDocument(myObject);
When creating a document, the attributes of the object will be stored as key-value pair E.g. in the previous example the object was stored as follows:
"name" : "Homer"
"age" : "38"
delete document
arangoDB.db("myDatabase").collection("myCollection").deleteDocument(myObject.getKey());
update document
arangoDB.db("myDatabase").collection("myCollection").updateDocument(myObject.getKey(), myUpdatedObject);
replace document
arangoDB.db("myDatabase").collection("myCollection").replaceDocument(myObject.getKey(), myObject2);
read document as JavaBean
MyObject document = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey(), MyObject.class);
document.getName();
document.getAge();
read document as VelocyPack
VPackSlice document = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey(), VPackSlice.class);
document.get("name").getAsString();
document.get("age").getAsInt();
read document as Json
String json = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey(), String.class);
read document by key
arangoDB.db("myDatabase").collection("myCollection").getDocument("myKey", MyObject.class);
read document by id
arangoDB.db("myDatabase").getDocument("myCollection/myKey", MyObject.class);