Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-31-2021 10:53 PM
I'd like to maintain a separate graphs for every client in my application. For such purpose I'd like to use the multi database feature of Neo4j 4.
In case of single backend logic for all clients, I have a following question - how to quickly navigate between databases based on the database name in every API call from client application? Do I only need to include ":use database_name" prior to each Cypher query in a scope of the same transaction or how? Will it be effective from a performance point of view?
06-01-2021 11:04 AM
If you are using the Neo4jClient
, you can quickly change the database that is used for the query with the in
method.
Flux<Map<String, Object>> allActors = client
.query("MATCH .....")
.in("myDatabase")
.fetch()
.all();
06-01-2021 11:20 PM
Thanks for your answer! But under the hood it still be two separate commands - ":use database_name" and then MATCH query ?
06-02-2021 01:47 AM
No, under the hood there is the Bolt protocol in place used by the drivers.
It communicates directly with the dbms and tells it to use this specific database during the session when the communication for a session starts.
06-02-2021 02:21 AM
Thanks, understood. But how about in case of SDN repository method? In case I'm going to execute MATCH on the particular database, before of that I have to execute another Cypher query with ":use database_name" in the same transaction?
06-03-2021 03:42 AM
No, this won't work as you would expect this.
Instead you will have to use the dynamic database selection feature.
This means controlled by some data within you application, you know which database to select and return its name on demand.
An example with Spring Security can be found here: Spring Data Neo4j Reference documentation - Dynamically configured database name
Sadly I cannot recap this right out of my head but I am pretty sure that there is some Spring feature that allows you to share the information coming in from the request with the context and the outcome of the dynamic database name source.
All the sessions of the conference are now available online