Neo4j Connector | MuleSoft Documentation
# Neo4j Connector
Neo4j Connector v3.0
Anypoint Connector for Neo4j provides the capability to execute CQL statements and run basic operations, such as create, update, delete, and select nodes against a Neo4j Graph database instance.
Release Notes: Neo4j Connector Release Notes Exchange: Neo4j Connector
## Before You Begin
To use this information, you need to be familiar with Neo4j, Mule, Anypoint Connectors, Anypoint Studio, Mule concepts, elements in a Mule flow, and Global Elements.
You need login credentials to test your connection to your target resource.
For software requirements and compatibility information, see the Connector Release Notes.
## POM File Information
```
<dependency>
 <groupId>com.mulesoft.connectors</groupId>
 <artifactId>mule-neo4j-connector</artifactId>
 <version>x.x.x</version>
 <classifier>mule-plugin</classifier>
</dependency>
```

Replace `x.x.x` with the version that corresponds to the connector you are using.
To obtain the most up-to-date `pom.xml` file information, access the connector in Anypoint Exchange and click **Dependency Snippets**.
## Metadata
Neo4j connector metadata is based on the following premises:
  * Labels listed on operations are the labels that are instanced in the database.
  * The database has these constraints for its nodes:
    * Unique property constraints.
    * Property existence constraints.
    * At least one node with constraint values defined in the database.


## Add the Connector to a Studio Project
Anypoint Studio provides two ways to add the connector to your Studio project: from the Exchange button in the Studio taskbar or from the Mule Palette view.
### Add the Connector Using Exchange
  1. In Studio, create a Mule project.
  2. Click the Exchange icon **(X)** in the upper-left of the Studio task bar.
  3. In Exchange, click **Login** and supply your Anypoint Platform username and password.
  4. In Exchange, search for "neo4j".
  5. Select the connector and click **Add to project**.
  6. Follow the prompts to install the connector.


### Add the Connector in Studio
  1. In Studio, create a Mule project.
  2. In the Mule Palette view, click **(X) Search in Exchange**.
  3. In **Add Modules to Project** , type "neo4j" in the search field.
  4. Click this connector’s name in **Available modules**.
  5. Click **Add**.
  6. Click **Finish**.


### Configure in Studio
  1. Drag a Neo4j operation to the Studio Canvas.
  2. Select the operation.
Name | Description  
---|---  
Execute any CQL statement against DB.  
**Create Node** |  Create a node with a specific initial label. Optionally, properties for the node can be added.  
**Select Nodes** |  Query nodes with a specific label. Optionally, properties used as filter can be provided.  
**Update Nodes** |  Modified properties for one or multiple nodes with a specific label. Optional Properties can be added as search filter criteria.  
**Delete Nodes** |  Delete one or multiples nodes based on a specific label. This lets you delete nodes with inbound/outbound relationships. Optional Properties can be added as search filter criteria.  
Note: The Neo4j connector’s basic operations can filter nodes by only one label in its query. If you want to filter in a query by multiple labels, use the Execute operation with a proper CQL statement.
  3. Configure the Global element for the connector.
Field | Description  
---|---  
Enter the username to log in with.  
Enter the corresponding password.  
Bolt endpoint.  
Rest endpoint URL (works with HTTP or HTTPS).  


## Use Case: Node Basic CRUD
  1. Create a new Mule Project in Anypoint Studio and set your Neo4j environment properties in `src/main/resources/automation-credentials.properties`.
```
config.username=<USERNAME>
config.password=<PASSWORD>
config.boltUrl=<BOLT_URL_ENDOPOINT>
config.restUrl=<REST_URL_ENDPOINT>
```

  2. Drag an HTTP connector onto the canvas and configure it with the default values.
  3. Drag a Transform Message onto the canvas and create a flowVar called params with the following code:
```
%dw 2.0
%output application/json
---
{
	"name":"Tom Hanks",
	"born": 1956
}
```

  4. Drag the Neo4j connector onto the canvas and configure a new global element according to the table below:
Parameter | Value  
---|---  
`${neo4j.username}`  
`${neo4j.password}`  
`${neo4j.boltUrl}`  
`${neo4j.restUrl}`  
```
<neo4j:config name="Neo4j_Config" doc:name="Neo4j Config">
	<neo4j:connection username="${config.username}"
	password="${config.password}"
	boltUrl="${config.boltUrl}"
	restUrl="${config.restUrl}" />
	</neo4j:config>
</neo4j:config>
```

  5. In the Properties Editor, configure:
Parameter | Value  
---|---  
**Display Name** |  Create node  
**Connector Configuration** |  Neo4j__Basic_Authentication  
Create node  
**Parameters Reference**  
Note: Click Test Connection to confirm that Mule can connect with the Neo4j instance. If the connection is successful, click OK to save the configuration. Otherwise, review or correct any invalid parameters and test again.
  6. Drag a Neo4j connector onto the canvas, in the Properties Editor, configure the parameters:
Parameter | Value  
---|---  
Select nodes  
  7. Drag a Neo4j connector onto the canvas, in the Properties Editor, configure the parameters:
Parameter | Value  
---|---  
Delete nodes  
  8. Drag an Transform Message onto the canvas.
```
%dw 2.0
%output application/json
---
payload
```

  9. Save the changes and deploy the project as a Mule Application. Open a browser and make a request to the following URL:
```
http://localhost:8081/CRUD
```

If the node was successfully created and deleted, information displays in a JSON format:
```
{"born":1956,"name":"Tom Hanks"}
```



### Create a Node with Multiple Labels
  1. Create a new Mule Project in Anypoint Studio and set your Neo4j environment properties in `src/main/resources/automation-credentials.properties`.
```
config.username=<USERNAME>
config.password=<PASSWORD>
config.boltUrl=<BOLT_URL_ENDOPOINT>
config.restUrl=<REST_URL_ENDPOINT>
```

  2. Drag an HTTP connector onto the canvas and configure it with the default values.
  3. Drag a Transform Message onto the canvas and create two flowVars with the following code:
    1. Variable-create
```
%dw 2.0
%output application/json
---
"CREATE (a:ACTOR:PERSON { name:\"Tom Hanks\", born:1956 })"
```

    2. Variable-select
```
%dw 2.0
%output application/json
---
"MATCH (a:ACTOR:PERSON) RETURN a"
```

  4. Drag the Neo4j connector onto the canvas and configure a new Global Element according to the table below:
Parameter | Value  
---|---  
`${neo4j.username}`  
`${neo4j.password}`  
`${neo4j.boltUrl}`  
`${neo4j.restUrl}`  
```
<neo4j:config name="Neo4j_Config" doc:name="Neo4j Config">
	<neo4j:connection username="${config.username}"
	password="${config.password}"
	boltUrl="${config.boltUrl}"
	restUrl="${config.restUrl}" />
	</neo4j:config>
</neo4j:config>
```

  5. In the Properties Editor, configure:
Parameter | Value  
---|---  
**Display Name** |  Create node (advanced)  
**Connector Configuration** |  Neo4j__Basic_Authentication  
`#[vars.create]`  
**Parameters Reference**  
Click Test Connection to confirm that Mule can connect with the Neo4j instance. If the connection is successful, click OK to save the configuration. Otherwise, review or correct any invalid parameters and test again.
  6. Drag a Neo4j connector onto the canvas, in the Properties Editor, configure the parameters:
Parameter | Value  
---|---  
**Display Name** |  Select node (Multi-label)  
`#[vars.select]`  
  7. Drag a Transform Message onto the canvas.
  8. Drag a Logger onto the canvas.
  9. Save the changes and deploy the project as a Mule Application. Open a browser and make a request to the following URL:
```
http://localhost:8081/createNodeMultiLabel
```

If the node was successfully created and deleted, information displays in a JSON format:
```
[{"a":{"born":1956,"name":"Tom Hanks"}}]
```
5. In the Properties Editor, configure:
Parameter | Value  
---|---  
**Display Name** |  Create node (advanced)  
**Connector Configuration** |  Neo4j__Basic_Authentication  
`#[vars.create]`  
**Parameters Reference**  
Click Test Connection to confirm that Mule can connect with the Neo4j instance. If the connection is successful, click OK to save the configuration. Otherwise, review or correct any invalid parameters and test again.
  6. Drag a Neo4j connector onto the canvas, in the Properties Editor, configure the parameters:
Parameter | Value  
---|---  
**Display Name** |  Select node (Multi-label)  
`#[vars.select]`  
  7. Drag a Transform Message onto the canvas.
  8. Drag a Logger onto the canvas.
  9. Save the changes and deploy the project as a Mule Application. Open a browser and make a request to the following URL:
```
http://localhost:8081/createNodeMultiLabel
```

If the node was successfully created and deleted, information displays in a JSON format:
```
[{"a":{"born":1956,"name":"Tom Hanks"}}]
```



## Use Case: XML
```
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:neo4j="http://www.mulesoft.org/schema/mule/neo4j"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
	http://www.mulesoft.org/schema/mule/neo4j
	http://www.mulesoft.org/schema/mule/neo4j/current/mule-neo4j.xsd">
	<http:listener-config name="HTTP_Listener_config"
	doc:name="HTTP Listener config" basePath="/" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<neo4j:config name="Neo4j_Config" doc:name="Neo4j Config">
		<neo4j:connection username="${config.username}"
		 password="${config.password}" boltUrl="${config.boltUrl}"
		 restUrl="${config.restUrl}" />
	</neo4j:config>
	<flow name="CRUD" >
		<http:listener doc:name="Listener"
		 config-ref="HTTP_Listener_config" path="/CRUD"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
	"name":"Tom Hanks",
	"born": "1956"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<neo4j:create-node label="Person" doc:name="Create node"
		 config-ref="Neo4j_Config" input="#[payload]"/>
		<neo4j:select-nodes label="Person" doc:name="Select nodes"
		 config-ref="Neo4j_Config" input="#[payload]"/>
		<neo4j:delete-nodes label="Person" doc:name="Delete nodes"
		 config-ref="Neo4j_Config" parameters="#[payload]"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
	<flow name="createNodeWithMultiLabels">
		<http:listener doc:name="Listener"
		config-ref="HTTP_Listener_config"
		path="/createNodeMultiLabel"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
}]]></ee:set-payload>
			</ee:message>
			<ee:variables >
				<ee:set-variable variableName="select" ><![CDATA[%dw 2.0
output application/json
---
"MATCH (a:ACTOR:PERSON) RETURN a"]]></ee:set-variable>
				<ee:set-variable variableName="create" ><![CDATA[%dw 2.0
output application/json
---
"CREATE (a:ACTOR:PERSON { name:\"Tom Hanks\", born:1956 })"]]></ee:set-variable>
			</ee:variables>
		</ee:transform>
		<neo4j:execute doc:name="Create node (advanced)" config-ref="Neo4j_Config" input="#[payload]">
			<neo4j:query ><![CDATA[#[vars.create]]]></neo4j:query>
		</neo4j:execute>
		<neo4j:execute doc:name="Select node (Multi-label)" config-ref="Neo4j_Config">
			<neo4j:query ><![CDATA[#[vars.select]]]></neo4j:query>
		</neo4j:execute>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
</mule>
```

## See Also
  * Neo4j Connector Reference
  * MuleSoft Help Center