I am trying to execute following JS file using arangosh in order to build my graph. The file executes without error but when I go into web interface, I do see a graph created but no vertices or edges in the graph.
db._dropDatabase("database");
db. _createDatabase("database", [], [{username: "admin", passwd: "admin", active: true}]);
db._useDatabase("database");
var graph_module = require("org/arangodb/general-graph");
var graph = graph_module._create("myGraph");
//Add top level documents
graph._addVertexCollection("users");
graph._addVertexCollection("positions");
graph._extendEdgeDefinitions(graph_module._relation("has_worked_at", ["users"], ["positions"]));
I save this file as database.js and then run following command
arangosh --javascript.execute database.js
The graph was created, the two vertex collections and the edge collection as well, but they do not contain any documents (vertices and edges). If you add
db.users.insert({_key:"Max"});
db.positions.insert({_key:"ArangoDB"});
db.has_worked_at.insert("users/Max", "positions/ArangoDB", {developer:true});
to your script, you will see two vertices and an edge in the graph viewer.
Related
I'm trying to add edges directly from the Arango WebUI-Graphs interface.
However, the interface complaints that:
Could not create edge: edge collection not used in graph
I'm actually using an edge collection in my graph, so it is unclear how to troubleshoot this error.
This is a bug with the web interface, and has been fixed in v3.5.0.
If you are not able to update to this version, you can create edges directly through the AQL interface:
<code>INSERT {
_from: "collection/vertex-id",
_to: "collection/vertex-id",
<your-other-properties>
} INTO <your-edge-collection>
</code>
I'm just starting out with Neo4j and I've been trying to send over simple relationships using Postman. I'm not having any issues sending the Nodes but the second I try to create a relationship, it creates two arbitrary grey nodes and builds the relationships. However, when I send a command like this:
CREATE (a:Person { name:'Tom Hanks', born:1956 })
-[r:ACTED_IN { roles: ['Forrest']}]->
(m:Movie { title:'Forrest Gump',released:1994 })
It properly displays the nodes and the relationship between them. See image below for more clarity.
This seems a bit odd as I would assume you'd be able to easily add nodes or create relationships at any point rather than when the Node's are being created.
Any feedback would be greatly appreciated.
Yes, you can create Relationship after the node is created using Match clause.
For e.g.
MATCH (node1:node),(node2:node)
WHERE node1.val=20 AND node2.val=21
CREATE (node1)-[r:Rel]->(node2)
RETURN r
Is there a way to dump the graphstructure of an arangoDB database, since
arangodump unfortunately just dumps the data of edges and collections.
According to the documentation in order to dump structural information of all collections (including system collections) you run the following
arangodump --dump-data false --include-system-collections true --output-directory "dump"
If you do not want the system collections to be included then don't provide the argument (it defaults to false) or provide a false value.
How is the structural and data of collections dumped, see below from the documentation
Structural information for a collection will be saved in files with
name pattern .structure.json. Each structure file will contains a JSON
object with these attributes:
parameters: contains the collection properties
indexes: contains the collection indexes
Document data for a collection will be saved in
files with name pattern .data.json. Each line in a data file is a
document insertion/update or deletion marker, alongside with some meta
data.
For testing I often want to extract a subgraph with a known structure. I use that to test my queries against. The method is not pretty but it might address your question. I blogged about it here.
Although #Raf's answer is accepted , --dump-data false will only give structure files for all the collections and but data wont be there. Including --include-system-collections true would give _graphs system collection's structure which wont have information pertaining to individual graphs creation/structure.
For Graph creation data as well
Right command is as follows.
arangodump --server.database <DB_NAME> --include-system-collections true --output-directory <YOUR_DIRECTORY>
We would be interested in _graphs_<long_id>.data.json named file which has below data format.
{
"type": 2300,
"data":
{
"_id": "_graphs/social",
"_key": "social",
"_rev": "_WaJxhIO--_",
"edgeDefinitions": [
{
"collection": "relation",
"from": ["female", "male"],
"to": ["female", "male"]
}
],
"numberOfShards": 1,
"orphanCollections": [],
"replicationFactor": 1
}
}
Hope this helps other users who were looking for my requirement!
Currently ArangoDB manages graphs via documents in the system collection _graphs.
One document equals one graph. It contains the graph name, involved vertex collections and Edge Definition that configure the directions of edge collections.
A deployment script creates and configures databases, collections, etc. The script includes code to drop databases before beginning so testing them can proceed normally. After dropping the database and re-adding it:
var graphmodule = require("org/arangodb/general-graph");
var graphList = graphmodule._list();
var dbList = db._listDatabases();
for (var j = 0; j < dbList.length; j++) {
if (dbList[j] == 'myapp')
db._dropDatabase('myapp');
}
db._createDatabase('myapp');
db._useDatabase('myapp');
db._create('appcoll'); // Collection already exists error occurs here
The collections that had previously been added to mydb remain in mydb, but they are empty. This isn't exactly a problem for my particular use case since the collections are empty and I had planned to rebuild them anyway, but I'd prefer to have a clean slate for testing and this behavior seems odd.
I've tried closing the shell and restarting the database between the drop and the add, but that didn't resolve the issue.
Is there a way to cleanly remove and re-add a database?
The collections should be dropped when db._dropDatabase() is called.
However, if you run db._dropDatabase('mydb'); directly followed by db._createDatabase('mydb'); and then retrieve the list of collections via db._collections(), this will show the collections from the current database (which is likely the _system database if you were able to run the commands)?.
That means you are probably looking at the collections in the _system database all the time unless you change the database via db._useDatabase(name);. Does this explain it?
ArangoDB stores additional information for managed graphs;
Therefore when working with named graphs, you should use the graph management functions to delete graphs to make shure nothing remains in the system:
var graph_module = require("org/arangodb/general-graph");
graph_module._drop("social", true);
The current implementation of the graph viewer in the management interface stores your view preferences (like the the attribute that should become the label of a graph) in your browsers local storage, so thats out of the reach of these functions.
I am creating a picture using d3, the picture is composed from node and link (arrow):
var graph = { nodes: d3.map(), edges: d3.map() };
Is there way to save nodes and edges using node.js to be able to restore it later?