// create database
arangoDB.createDatabase("myDatabase");
// drop database
arangoDB.db("myDatabase").drop();
// create collection
arangoDB.db("myDatabase").createCollection("myCollection", null);
// delete collection
arangoDB.db("myDatabase").collection("myCollection").drop();
arangoDB.db("myDatabase").collection("myCollection").truncate();
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
*/
}
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"
arangoDB.db("myDatabase").collection("myCollection").deleteDocument(myObject.getKey);
arangoDB.db("myDatabase").collection("myCollection").updateDocument(myObject.getKey, myUpdatedObject);
arangoDB.db("myDatabase").collection("myCollection").replaceDocument(myObject.getKey, myObject2);
MyObject document = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey, MyObject.class);
document.getName();
document.getAge();
VPackSlice document = arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey, VPackSlice.class);
document.get("name").getAsString();
document.get("age").getAsInt();
arangoDB.db("myDatabase").collection("myCollection").getDocument(myObject.getKey, String.class);
arangoDB.db("myDatabase").getDocument("myCollection/myKey", MyObject.class);