neo4jphp: creation of unique nodes

166 views
Skip to first unread message

samar uppal

unread,
Sep 23, 2012, 5:41:43 AM9/23/12
to Neo4j

Am using the neo4jphp library in order to create my graph. But the
below code is duplicating my codes. I don't see the REST API providing
any of enforcing uniqueness of a node during node creation.

$batch = new Everyman\Neo4j\Batch($client);
while ($row = mysql_fetch_array($user_rels, MYSQL_NUM)) {
$usernode = $client->makeNode();
$usernode->setProperty('name', $row[1])
->setProperty('guid', $row[0])
->setProperty('type', 'user')
->save();
}
$batch-commit()



Thanks,
Samar

Josh Adell

unread,
Sep 23, 2012, 3:24:53 PM9/23/12
to ne...@googlegroups.com
Samar,

The REST API does not do any uniqueness checking when you ask it to create a node. If you want to create a unique node, you need to add it to an index and specify that the node should only be created in the index if it does not already exist.

neo4jphp does not currently support this, but there is active discussion about how best to go about it. It should be in the library soon. If you have immediate need for it, you can always query for a node with the unique properties and see if it exists before creating it.

Also, in your code, just creating a new Batch object doesn't do anything. You should use $client->startBatch() and $client->commitBatch()

-- Josh

Tatham Oddie

unread,
Sep 23, 2012, 5:38:45 PM9/23/12
to ne...@googlegroups.com

Alternatively, if neo4jphp supports Cypher, you could use the CREATE UNIQUE clause there.

--
 
 

Josh Adell

unread,
Sep 23, 2012, 10:34:44 PM9/23/12
to ne...@googlegroups.com
Good point, Tatham, thanks.

Yes, neo4jphp does support Cypher, but not in Batch operations. However, you can use Cypher to create multiple nodes at once, and they will all be created in a single transaction.

-- Josh

Michael Hunger

unread,
Sep 23, 2012, 9:54:19 AM9/23/12
to ne...@googlegroups.com
There is a create unique node REST api call at least

--


unixx

unread,
Sep 24, 2012, 11:42:35 AM9/24/12
to ne...@googlegroups.com


Thanks for the tips folks! For now, am checking on the client side for duplicates. Will look into implementing the unique indexes rest api call for neo4jphp.

We have a great forum going on here. 
;)

Michael Hunger

unread,
Sep 24, 2012, 12:02:14 PM9/24/12
to ne...@googlegroups.com
Create unique doesn't create unique nodes

Sent from mobile device
--
 
 

Krishna Shetty

unread,
Oct 14, 2013, 2:07:56 AM10/14/13
to ne...@googlegroups.com, uppal...@gmail.com
Can create uniqueness using lables? 
Like:
CREATE CONSTRAINT ON (n:user) ASSERT n.guid IS UNIQUE;

Thanks,Krishna

Peter Neubauer

unread,
Oct 16, 2013, 7:58:57 AM10/16/13
to Neo4j User, uppal...@gmail.com


G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

The Neo4j Browser  - Neo4j 2.0.0-M06
Graphs+Beer         = GraphCafe Malmö Oct 23rd
Got some data?        There is a graph for this.


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages