1

I am just starting with neo4j database. I am using neomodel in Python, to connect with neo4j.

For this, I created a new database with name "kat" and gave it a password - "password".

After running the following code, I am able to create a new person called Jim in the database:

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

What I don't understand is, I have not mentioned the name of the database anywhere in the code, but still I can see this node being created in the db. Can anyone explain? I used this as a setup guide - https://neomodel.readthedocs.io/en/latest/getting_started.html

Kshitij Mittal
  • 2,698
  • 3
  • 25
  • 40

1 Answers1

1

There is only one database active in neo4j and It's defined in conf/neo4j.conf file.

You can create more databases and but cannot have multiple databases active at the same time.

If you want, you can change the active database in conf/neo4j.conf file.

Change below line to point to new database.

dbms.active_database=graph.db
Rajendra Kadam
  • 4,004
  • 1
  • 10
  • 24
  • This statement is not completely true as of Neo4j 4+. You can select the database you want to use programmatically via neo4j driver. I am not sure how neomodel handles that. – locorecto Jan 12 '21 at 14:49
  • Yes, This was answered for the older version of the Neo4j. You can check if the Neomodel has a new version – Rajendra Kadam Jan 12 '21 at 16:07