node.js - 使用数组查询 cassandra 数据库

标签 node.js express cassandra cassandra-driver

我正在尝试查询我的 cassandra 数据库以从阵列服务器端保存的名称列表返回数据。这是作为一个数组保存的。 我知道我正在访问的数据作为字符串存储在我的数据库中,因此我在它周围附加了单引号(我尝试过使用和不使用它,但没有运气)。

这是我的查询。

const arr = ["ukcust1","ukcust2","ukcust5"];
//Here I append single quotes before and after to each string if needed

const query = "SELECT * FROM table_name WHERE name = ?";
client.execute(query, arr, { prepare:true }, function (err, result) {
..//Code
};

我在这里缺少什么?我希望查询是:

SELECT * FROM table_name WHERE name = each of the names in the array 'arr';

最佳答案

如果 name 是集群键,那么您可以使用“in”和“允许过滤”进行查询,如下所示:

select * from table_name where name in ('ukcust1','ukcust2','ukcust3') 允许过滤

假设名称不是集群键,您可以使用集群键(例如,date_of_birth),如果它具有逻辑意义 - 也就是说,如果按日期过滤相对于名称有意义 - 如下所示:

select * from table_name where date_of_birth in (1969, 1972) name in ('ukcust1','ukcust2','ukcust3') 允许过滤

如果您无法执行上述任何操作,则需要使用 Javascript(例如 foreach)循环遍历数组。

关于node.js - 使用数组查询 cassandra 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50330801/

相关文章:

node.js - 我们如何在Microsoft Bot Framework中为不同的用户维护不同的 session ?

node.js - 使用 Node.js 在 Redis 中搜索然后添加记录

node.js - 如何从 Node 应用程序手动上传文件到服务器

docker - Docker 中的 Cassandra 无法从外部连接

Cassandra 批处理准备语句大小警告

javascript - Promise then() 和 catch() UnhandledPromiseRejectionWarnin

php - 从node.js请求JSON文件到PHP

javascript - ZEIT 现在无服务器函数 - 带参数的路由

node.js - 无法为 Express.js 应用程序 (CORS) 设置 header

Cassandra启动