如何在mongodb robo3t控制台中根据字符串类型日期进行查询?

时间:2018-03-06 14:00:27

标签: mongodb robo3t

在mongodb集合中,我有一个变量DateTimeAsString,其值为04-26-2017 11:51:40:445。

当我尝试执行这样的事情时 db.getCollection('collection').find({dateTimeAsString: { "$gte": ISODate("2018-03-05"),"$lte": ISODate("2018-03-06") }})

它返回0个文件。

我尝试使用$ where运算符并将DateTimeAsString转换为Date,但它仍然返回0个文档。

db.getCollection('collection').find({$where : function() {
var date = new Date(this.dateTimeAsString)
var newdate=new Date("2018-03-05 00:00:00");
if (date > newdate)
    return this
}}).count()

注意 - 我想在Robo3t控制台中使用它。

感谢。

0 个答案:

没有答案