got "Neo.ClientError.Cluster.NotALeader" in node js using neo4j-ha-bolt-driver

254 views Asked by At

I use neo4j-ha-bolt-driver module to connect to neo4j cluster. I connected to neo4j and tried an update query but I got "Neo4jError: No write operations are allowed directly on this database. Writes must pass through the leader. The role of this server is: FOLLOWER". Any idea how to solve this?

var Neo4jHA = require("neo4j-ha-bolt-driver");
const servers = [
    ["http://neo4j-core1", "bolt://neo4j-core1"],
    ["http://neo4j-core2", "bolt://neo4j-core2"],
    ["http://neo4j-core3", "bolt://neo4j-core3"],
    ["http://neo4j-core4", "bolt://neo4j-core4"],
    ["http://neo4j-core5", "bolt://neo4j-core5"],
];
const auth = { user: "user", pass: "pass" };
const strategy = Neo4jHA.HAStrategies.roundRobin;
const rwConfig = Neo4jHA.HAReadWrite.all;
const checkInterval = 500;
let time = timestamp('YYYY-MM-DD hh:mm:ss.iii');
const driver = new Neo4jHA(
    servers,
    { auth, strategy, rwConfig, checkInterval },
    (readyCallback) => {
        session = driver.session(true);
        session.run("match (n:student) where n.student_id= 3 set n.time= '" + time + "'")
            .subscribe({
                onCompleted: function () {
                    console.log('updated')
                },
                onError: function (err) {
                    console.log(err)
                }
            })
    });
1

There are 1 answers

1
Tomaž Bratanič On

The last version of neo4j-ha-bolt-driver package is from 4 years ago. Lots of things have changed in the meantime and it is no surprise that the 4-year-old package is not working as expected.

I would suggest you use the official Neo4j JS driver: https://github.com/neo4j/neo4j-javascript-driver