简体   繁体   English

Node.js Google Cloud Platform数据存储日期比较

[英]Node.js Google Cloud Platform Datastore date comparison

I'd like to run a query on Google Datastore using gcloud.js module: 我想使用gcloud.js模块在Google数据存储区上运行查询:

var startDate = moment('2016-03-11').format('YYYY-MM-DD');
var query = exports.dataset.createQuery('Resource')
  .filter('startDate', '>=', startDate);
exports.dataset.runQuery(query, function(err, resources) {
  console.log(resources);
});

This date comparison filter is not working, displaying all possible entities. 此日期比较过滤器不起作用,显示所有可能的实体。 Other filter types work perfectly fine. 其他过滤器类型也可以正常工作。

I don't know in which format should I pass the date. 我不知道我应该以哪种格式传递日期。 Tried almost every possible format. 尝试了几乎所有可能的格式。 Maybe the comparison operator for date should be different? 也许日期的比较运算符应该不同?

The problem is with the variable type. 问题出在变量类型上。 It can't be a string, it shuold be parsed to Date: 它不能是字符串,应该解析为Date:

.filter('startDate', '>=',  new Date(startDate));

Now everything works like a charm. 现在,一切都像魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM