Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a node in neo4j with specified id?

Tags:

php

neo4j

I want to hold relationships in neo4j but (maybe, I've not decided yet) to keep the objects in different DB (sort of Redis). And if to do so, it would be good to sync IDs in storage db and in neo4j. So, can I create a node in neo4j passing the ID to it?

PS project in PHP and accessing neo4j via REST API.

like image 782
Terion Avatar asked Dec 24 '11 19:12

Terion


People also ask

Which one is correct when we create a node in Neo4j?

Creating a Single node You can create a node in Neo4j by simply specifying the name of the node that is to be created along with the CREATE clause.

What is ID in Neo4j?

In Neo4j, "Id" is a default internal property for both Nodes and Relationships. That means, when we create a new Node or Relationship, Neo4j Database Server will assign a number for internal usage. It is incremented automatically.

How do you represent a node in Cypher?

Node or Relationship Properties To represent these in Cypher, we can use curly braces within the parentheses of a node or the brackets of a relationship. The name and value of the property then go inside the curly braces. Our example graph has both a node property ( name ) and a relationship property ( since ).

How many nodes can a single relationship connect?

A relationship connects two nodes — a start node and an end node. Just like nodes, relationships can have properties. Relationships between nodes are a key part of a graph database.

Can a node have multiple labels Neo4j?

If you look closely, the labels column is in the form of an array, which means that a single node can have multiple labels. Also, with cypher projection, we can provide a virtual label, as shown in the query.


2 Answers

You normally can't, only if you use the BatchImporter, http://docs.neo4j.org/chunked/snapshot/indexing-batchinsert.html, you can specify the IDs to use.

like image 197
Peter Neubauer Avatar answered Sep 17 '22 20:09

Peter Neubauer


Otherwise it is sensible to use external id's as node properties and index the nodes on those properties. So you have bi-directional resolutions of your external id's.

The indexing can also be done using the auto-indexer, so it happens automatically on node creation, update and removal.

You might also look into Neo4jPHP as a library to access Neo4j's REST API.

like image 32
Michael Hunger Avatar answered Sep 19 '22 20:09

Michael Hunger