neo4j - Neo4jError: The client is unauthorized due to authentication failure
问题描述
I am newbie to neo4j. I am using javascript driver . Need to know what i am doing wrong . I am attaching code snippet . Am I missing something ? Please guide me.
app.js
var express = require('express');
var bodyParser = require('body-parser');
var neo4j = require('neo4j-driver').v1;
var app = express();
app.use(bodyParser.json());
var driver = neo4j.driver('bolt://localhost', neo4j.auth.basic("neo4j", "neo4j"));
var session = driver.session();
session
.run('MERGE (alice:Person {name : {nameParam} }) RETURN alice.name AS name', {nameParam: 'Alice'})
.subscribe({
onNext: function (record) {
console.log(record.get('name'));
},
onCompleted: function () {
session.close();
},
onError: function (error) {
console.log(error);
}
});
/* Start the express App and listen on port 8080 */
var initServer = function () {
var server = app.listen(8080);
console.log('info', '*********** Application Server is listening on Port 8080 ***********');
};
initServer();
解决方案
I briefly bumped into the same problem earlier today. But then I remembered that when I started the neo4j server earlier, I had navigated to http://localhost:7474 from the browser and signed in using the default credentials username=neo4j and password=neo4j, which then prompted me to create a new password before I could proceed.
My hunch is that you probably have not changed the default password, which you need to. After that, you should have no problem with authentication. Use the short program below you check if you are good. Create a file index.js and add this:
const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "YOUR_NEW_PASSWORD"));
const session = driver.session();
const personName = 'Alice';
session.run(
'CREATE (a:Person {name: $name}) RETURN a',
{name: personName})
.then(result => {
session.close();
const singleRecord = result.records[0];
const node = singleRecord.get(0);
console.log(node.properties.name);
// on application exit:
driver.close();
})
.catch(error => console.log(error));
The using nodejs, simply execute this from the command prompt:
node index.js
You should see the output "Alice" on the command line
推荐阅读
- java - Google 登录无法在已发布的应用上运行
- javascript - 带有错误消息的jQuery多个下拉类过滤器
- grafana - visualization graph Grafana
- sql-server - 顺序列名
- ios - 在 iOS 的自定义框架中嵌入 coredata
- java - 对于 MongoClient 类型,方法 getDatabase(String) 未定义
- css - css解析在生产中失败
- c# - 如何打印作为字符串动态列表的所有列表值
- jdbc - Apache Kafka JDBC 连接器 - SerializationException: Unknown magic byte
- amazon-web-services - 使用 nginx 作为 AWS S3 存储桶的反向代理,将我重定向到 https://aws.amazon.com/s3/