2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to create a collection in arangodb and insert a document in arangodb using java code?

Now i want to create a new collection and insert a document in that collection using java driver. How will i do that?
userimage

Add the arangodb java driver

<dependency>
    <groupId>com.arangodb</groupId>
    <artifactId>arangodb-java-driver</artifactId>
    <version>3.0.0</version>
</dependency>


Now get the connection from arangodb [for reference click here]

Now to create a new collection try as below:

ArangoDBConnection.getDB().createCollection(<Collection name>);

and to insert a new document using java driver try as below:

BaseDocument baseDocument = new BaseDocument();
baseDocument.addAttribute("_key", "Moe");
baseDocument.addAttribute("firsrname", "Moe");
// keep adding more if required

ArangoDBConnection.getDB().createDocument(<Collection name>, baseDocument);


It will work for you.

Answer is