如何使用Node.js驱动程序将REQ.Body的数据发布到CQL UDT列中?
我是Cassandra的新手,我需要您的帮助。
使用CQL控制台创建收集表后,我能够创建新的记录并读取它们,但是使用nodejs中的Cassandra-Driver进行后操作不起作用,仅在使用CQL控制台时才有效。
我创建了表:
CREATE TYPE event_info (
type text,
pagePath text,
ts text,
actionName text
);
CREATE TABLE journey_info_5 (
id uuid PRIMARY KEY,
user_id text,
session_start_ts timestamp,
event FROZEN<event_info>
);
邮政操作的代码:
export const pushEvent = async(req,res)=>{
const pushEventQuery = 'INSERT INTO user_journey.userjourney (id, user_id, session_start_ts,events)
VALUES ( ${types.TimeUuid.now()}, ${req.body.user_id},${types.TimeUuid.now()},
{ ${req.body.type},${req.body.pagePath},${req.body.ts},${req.body.actionName}} } );'
try {
await client.execute(pushEventQuery)
res.status(201).json("new record added successfully");
} catch (error) {
res.status(404).send({ message: error });
console.log(error);
}
}
它给出错误,如何从用户中获取数据并在此集合中发布? 如果有的话,请帮助我
I am new to cassandra I need your help.
After creating a collection table using cql console, I am able to create new records and read them, but Post operation using cassandra-driver in nodejs is not working, it only works when I use cql console.
I created table:
CREATE TYPE event_info (
type text,
pagePath text,
ts text,
actionName text
);
CREATE TABLE journey_info_5 (
id uuid PRIMARY KEY,
user_id text,
session_start_ts timestamp,
event FROZEN<event_info>
);
codes for post operation:
export const pushEvent = async(req,res)=>{
const pushEventQuery = 'INSERT INTO user_journey.userjourney (id, user_id, session_start_ts,events)
VALUES ( ${types.TimeUuid.now()}, ${req.body.user_id},${types.TimeUuid.now()},
{ ${req.body.type},${req.body.pagePath},${req.body.ts},${req.body.actionName}} } );'
try {
await client.execute(pushEventQuery)
res.status(201).json("new record added successfully");
} catch (error) {
res.status(404).send({ message: error });
console.log(error);
}
}
it is giving errors, How can I get data from user and post in this collection?
please help me, if any idea
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您的CQL语句无效。用于在用户定义类型(UDT)列中插入值的格式是:
请注意,模式中的列名与您的代码中的CQL语句不匹配,因此我在此处重新启动架构,以确保
: CQL语句我用来将UDT插入表中(格式化以可读性):
有关参考,请参见将数据插入或更新到UDT列。干杯!
The issue is that your CQL statement is invalid. The format for inserting values in a user-defined type (UDT) column is:
Note that the column names in your schema don't match up with the CQL statement in your code so I'm reposting the schema here for clarity:
Here's the CQL statement I used to insert a UDT into the table (formatted for readability):
For reference, see Inserting or updating data into a UDT column. Cheers!