python中的neomodel如何连接没有db name的neo4j db?

2024-05-20 02:31:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是从neo4j数据库开始。我正在用Python中的neomodel连接neo4j

为此,我创建了一个名为“kat”的新数据库,并给它一个密码——“password”。你知道吗

运行以下代码后,我可以在数据库中创建一个名为Jim的新人员:

from neomodel import (config, StructuredNode, StringProperty, IntegerProperty,
    UniqueIdProperty, RelationshipTo, RelationshipFrom)

config.DATABASE_URL = 'bolt://neo4j:password@localhost:7687'

class Country(StructuredNode):
    code = StringProperty(unique_index=True, required=True)
    inhabitant = RelationshipFrom('Person', 'IS_FROM')


class Person(StructuredNode):
    uid = UniqueIdProperty()
    name = StringProperty(unique_index=True)
    age = IntegerProperty(index=True, default=0)
    country = RelationshipTo(Country, 'IS_FROM')


jim = Person(name='Jim', age=3).save()
jim.age = 4
jim.save() # validation happens here
# jim.delete()
# jim.refresh() # reload properties from neo
print(jim.id) # neo4j internal id

我不明白的是,我没有在代码的任何地方提到数据库的名称,但是我仍然可以看到这个节点正在数据库中创建。有人能解释一下吗?我用这个作为安装指南-https://neomodel.readthedocs.io/en/latest/getting_started.html


Tags: 代码fromconfig数据库trueageindexpassword
1条回答
网友
1楼 · 发布于 2024-05-20 02:31:45

在neo4j中只有一个数据库处于活动状态,它是在conf/neo4j.conf文件中定义的。你知道吗

可以创建更多数据库,但不能同时激活多个数据库。你知道吗

如果需要,可以更改conf/neo4j.conf文件中的活动数据库。你知道吗

更改下一行以指向新数据库。你知道吗

dbms.active_database=graph.db

相关问题 更多 >