1

私はneo4jデータベースから始めたばかりです。私はneo4jと接続するために、Pythonでneomodelを使用しています。

このために、「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

4

1 に答える 1

1

neo4j でアクティブなデータベースは1 つだけで、ファイルで定義されていconf/neo4j.confます。

さらにデータベースを作成できますが、複数のデータベースを同時にアクティブにすることはできません。

必要に応じて、ファイル内のアクティブなデータベースを変更できconf/neo4j.confます。

以下の行を新しいデータベースを指すように変更します。

dbms.active_database=graph.db
于 2019-02-15T09:20:03.657 に答える