Skip to content

Getting Connected

dajester2013 edited this page May 26, 2014 · 1 revision

The ArangoDB database communicates via a RESTful protocol, therefore the client connection is just an HTTP request factory, which requires no connection pooling. In a clustered environment, you need to have one connection per coordinator. In the future this may change so that the CFArango connection allows specifying multiple endpoints that would be used in rotation.

The following is an example of opening a connection.

<cfscript>
// all the following examples are representative of the defaults unless otherwise stated.

conn = new org.jdsnet.arangodb.Connection()
		.setHost("localhost")
		.setPort(8529)
		.setProtocol("http");

// this step is optional, but it allows setting the default database.
conn.setDatabase("_system");

// currently, the only supported credentials are for Basic Authentication, which for production means
// you must set up your ArangoDB endpoints with SSL!
conn.getCredentials()
	.setUsername("root")
	.setPassword("");

// this step is optional, but it ensures that the host is reachable.
// it requires that the configured credentials has access to the default database
conn.open();
</cfscript>

Things you can do with the connection:

<cfscript>
// these two operations require the configured credentials to have access to the default database:
    // get the version number of the configured ArangoDB host
    conn.getServerVersion();
    // get a list of the databases the user has access to
    conn.getUserDatabases();

// this provides the "low-level" API for communicating with ArangoDB.  Any functionality not implemented by
// a high-level API can be accessed via this method.
documentSvc = conn.openService("document",conn.getDatabase());

// gets the document data as the result
documentDataStruct = documentSvc.get("Document/id");

// gets all the response headers in addition to the response data
documentSvc.returnAll();
resultStruct = documentSvc.get("Document/id");
documentDataStruct = resultStruct.responseData;
</cfscript>

Clone this wiki locally