node.js - Cassandra 当前时间戳与 Node.js

标签 node.js express cassandra

在下面的插入查询中,当我使用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函数,可以在插入中使用

dateOf

关于node.js - Cassandra 当前时间戳与 Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44004617/

相关文章:

node.js - SailsJS 模型按条件计数

node.js - 以 express 形式提交表单时 CSRF token 不起作用

javascript - NodeJS Promise (Q) - 如果 promise 失败,如何获取值?

javascript - 错误 [ERR_UNSUPPORTED_DIR_IMPORT] : Directory import when attempting to start Nodejs App locally

javascript - 如何确保注销的用户永远不会在 Node、Express、Passport 和 Backbone 应用程序中看到某些哈希 Backbone 页面

cassandra - cassandra中主键上的模式匹配 'like'

c# - 我可以使用 Cassandra 来存储对象吗?

node.js - passport-linkedin-oauth2 不返回电子邮件地址

javascript - 给定计数的随机数

Cassandra Compaction 占用所有资源并导致节点故障