在下面的插入查询中,当我使用dateof(now())
时,它不起作用。但是new Date('2017-09-01 00:00:00+0000')
,这个正在工作。
router.post('/recent_activities', function(req, res, next) {
var body = req.body;
console.log(body);
console.log(body.id + body.setid);
var query = "Insert into recent_activities
(id, setid, companyid, activity_name, activity_date, activity_by) values( ? , ? , ? , ? , ? , ? )
"
client.execute(query, [body.id, body.setid, body.companyid, body.activity_name, dateof(now()), body.activity_by],
function(err, result) {
if (err) {
throw err;
} else {
console.log('success!');
}
});
res.json({ id: 201, message: 'All Success' });
});
我收到 500 内部服务器错误。
now is not defined
ReferenceError: now is not defined
at /apps/node_cassandra/routes/index.js:96:85
at Layer.handle [as handle_request]
(/apps/node_cassandra/node_modules/express/lib/router/layer.js:95:5)
at next
(/apps/node_cassandra/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch
(/apps/node_cassandra/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request]
(/apps/node_cassandra/node_modules/express/lib/router/layer.js:95:5)
at /apps/node_cassandra/node_modules/express/lib/router/index.js:281:22
最佳答案
dateOf()
Used in a SELECT clause, this function extracts the timestamp of a timeuuid column in a result set. This function returns the extracted timestamp as a date. Use unixTimestampOf() to get a raw timestamp.
根据文档 dateOf
用于 select 子句。
now()
用于生成插入的 timeuuid。
因此,如果您的列数据类型是 timeuuid,那么只有您可以使用 now()
。
如果是时间戳,则将日期插入为 new Date()
。
或者还有可用的toDate
函数,可以在插入中使用
关于node.js - Cassandra 当前时间戳与 Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44004617/