I would suggest using the indexing capabilities to solve this:
name_index = neo.index("name", create=True)
def get_node(id):
node = name_index[id]
if node is None:
node = neo.node(name=id)
name_index[id] = node
return node
Cheers,
Tobias
On Sat, Nov 14, 2009 at 6:51 PM, Yin Chen <[email protected]> wrote:
> Hi:
> I was playing with the Neo4j and its python binding. I want to import
> the user relationship data to Neo4j.
> Say id is the unique id for the user, I found no easy way to prevent the
> same id from generating different Nodes.
> The code below may works, but the data may be too big for memory.
>
> id_node_mapping = {}
> def get_node(id):
> if id in id_node_mapping:
> return id_node_mapping.get(id)
> else:
> node = neo.node(name=id)
> id_node_mapping[id] = node
> return node
>
> Any solution to this problem? Thanks.
> _______________________________________________
> Neo mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>
--
Tobias Ivarsson <[email protected]>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user