【发布时间】:2016-10-02 03:58:46
【问题描述】:
50 年来,我一直在尝试将 Node.js 与 Cassandra 连接到 localhost(感觉不错),但还没有弄清楚它们是如何协同工作的。我将不胜感激任何可能导致解决方案的建议。
项目目录:
project - app - some files
\- build - index.js, index.html, etc.(I start the server by "node index.js")
\- node_modules - some modules
\- signup - some files to be minified
\- signin - some files to be minified
\- apache-cassandra-3.0.6 - bin, conf, etc.(downloaded from tarball)
\- package.json
\- webpack.config.js
Webpack 运行没有任何问题,所以问题在 webpack 配置中不存在。
我可以使用cqlsh插入数据,所以问题不在于数据结构的模型。
我认为问题在于我对如何同时使用 Node.js 和 Cassandra 缺乏了解。
我将 Node.js 与 Cassandra 连接的过程:
- 进入构建目录
node index.js- 打开localhost:3000找到首页,通过express.js路由,显示没有问题。
- 转到注册页面并提交表单
- 错误(未插入数据)
我不确定哪个联系点是正确的,“127.0.0.1:9042”或“127.0.0.1”
var client = new cassandra.Client({contactPoints:['127.0.0.1:9042']});
OR
var client = new cassandra.Client({contactPoints:['127.0.0.1']});
我这样设置我的路由器。
var router = express.Router();
var insertUser = 'INSERT INTO keyspace.users (username, create_time, email, password) VALUES (?, ?, ?, ?);';
router.get"/", function(req, res) {
res.sendFile(__dirname + '/index.html'); // This is working.
});
router.post("/signup", function(req, res) {
var username = req.body.username;
var email = req.body.email;
var password = req.body.password;
client.execute(insertUser, [username, now(), email, password],
{ prepare: true }, function(err) {
if (err) {
console.log("error"); // I receive error.
} else {
console.log("success");
}
});
});
我应该让 cassandra 像这样在后台运行吗?
cd apache-cassandra-3.0.6 -> cd bin -> ./cassandra
我在这里错过了什么?
【问题讨论】:
-
您遇到的错误是什么(您可以在发生“错误”实例时记录它)吗?此外,您不需要将端口作为联系点的一部分提供,您可以将其作为 protocolOptions { port: 9042} 提供,即: new cassandra.Client({contactPoints:['127.0.0.1', protocolOptions { port: 9042 }}),但您不需要在此处执行此操作,因为 9042 是默认值。
-
服务器已启动{ [错误:所有主机尝试查询失败。第一个主机尝试,127.0.0.1:9042: AuthenticationError: Auth entication provider not set。请参阅 innerErrors。] innerErrors: { '127.0.0.1:9042': { [AuthenticationError: Authentication provider not set] name: 'AuthenticationError', stack: 'Error: Authentication provider not set\n at AuthenticationError.DriverError