Skip to content

Commit 9a8baca

Browse files
committed
API docs: elaborate on home database resolution
1 parent 29f9415 commit 9a8baca

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

docs/source/api.rst

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,41 @@ Name of the database to query.
566566
The default database can be set on the Neo4j instance settings.
567567

568568
.. Note::
569-
It is recommended to always specify the database explicitly when possible.
570-
This allows the driver to work more efficiently, as it will not have to
571-
resolve the home database first.
569+
570+
This option has no explicit value by default, but it is recommended to set
571+
one if the target database is known in advance. This has the benefit of
572+
ensuring a consistent target database name throughout the session in a
573+
straightforward way and potentially simplifies driver logic as well as
574+
reduces network communication resulting in better performance.
575+
576+
When no explicit name is set, the driver behavior depends on the connection
577+
URI scheme supplied to the driver on instantiation and Bolt protocol
578+
version.
579+
580+
Specifically, the following applies:
581+
582+
- **bolt schemes** - queries are dispatched to the server for execution
583+
without explicit database name supplied, meaning that the target database
584+
name for query execution is determined by the server. It is important to
585+
note that the target database may change (even within the same session),
586+
for instance if the user's home database is changed on the server.
587+
588+
- **neo4j schemes** - providing that Bolt protocol version 4.4, which was
589+
introduced with Neo4j server 4.4, or above is available, the driver
590+
fetches the user's home database name from the server on first query
591+
execution within the session and uses the fetched database name
592+
explicitly for all queries executed within the session. This ensures that
593+
the database name remains consistent within the given session. For
594+
instance, if the user's home database name is 'movies' and the server
595+
supplies it to the driver upon database name fetching for the session,
596+
all queries within that session are executed with the explicit database
597+
name 'movies' supplied. Any change to the user’s home database is
598+
reflected only in sessions created after such change takes effect. This
599+
behavior requires additional network communication. In clustered
600+
environments, it is strongly recommended to avoid a single point of
601+
failure. For instance, by ensuring that the connection URI resolves to
602+
multiple endpoints. For older Bolt protocol versions the behavior is the
603+
same as described for the **bolt schemes** above.
572604

573605

574606
.. code-block:: python

0 commit comments

Comments
 (0)