from arango import ArangoClient
- User
from arango import ArangoClient
- Assistant
from arango import ArangoClient
In ArangoDB, the ArangoClient class is used to connect to and interact with the database. The class provides methods for performing various database operations, such as querying data, inserting documents, updating documents, and deleting documents.
To create an instance of the ArangoClient class, you need to provide the host and port number of the ArangoDB server as arguments to the constructor. For example:
import arango
# Create an Arango client
client = arango.ArangoClient("localhost", 8529)
Once you have an instance of the ArangoClient class, you can use its methods to interact with the database. Here are some examples:
query method to execute queries against the database. This method takes two arguments: the first argument is the query statement as a string, and the second argument is a dictionary containing any required query parameters. For example:# Execute a query
query_result = client.query("FOR v IN clusters RETURN v.name")
In this example, we are querying for the names of all clusters in the database.
insert method to insert documents into the database. This method takes two arguments: the first argument is the document data as a dictionary, and the second argument is the collection to which the document should be inserted. For example:# Insert a document
client.insert("myCollection", {"name": "My Document", "content": "This is my document."})
In this example, we are inserting a document with the name "My Document" and content "This is my document." into the "myCollection" collection.
update method to update existing documents in the database. This method takes three arguments: the first argument is the document ID, the second argument is the document data as a dictionary, and the third argument is the collection name. For example:# Update a document
client.update("myDocument", {"name": "Updated Document", "content": "This is my updated document."}, "myCollection")
In this example, we are updating the document with ID "myDocument" in the "myCollection" collection to have the name "Updated Document" and content "This is my updated document."
delete method to delete documents from the database. This method takes two arguments: the first argument is the document ID, and the second argument is the collection name. For example:# Delete a document
client.delete("myDocument", "myCollection")
In this example, we are deleting the document with ID "myDocument" in the "myCollection" collection.