MongoDB + Node.js:如何查询ISODate字段? [英] MongoDB + nodejs : how to query ISODate fields?
问题描述
我正在将nodejs与node-mongodb-native驱动程序配合使用( http://mongodb.github.io/node -mongodb-native/).
I am using nodejs with the node-mongodb-native driver (http://mongodb.github.io/node-mongodb-native/).
我的文档的date属性存储为ISODate
类型.
I have documents with a date property stored as ISODate
type.
通过nodejs,我正在使用以下查询:
Through nodejs, I am using this query:
db.collection("log").find({
localHitDate: {
'$gte': '2013-12-12T16:00:00.000Z',
'$lt': '2013-12-12T18:00:00.000Z'
}
})
它什么也不返回.为了使其正常工作,我需要执行以下操作:
It returns nothing. To make it work I need to do the following instead:
db.collection("log").find({
localHitDate: {
'$gte': ISODate('2013-12-12T16:00:00.000Z'),
'$lt': ISODate('2013-12-12T18:00:00.000Z')
}
})
但是在我的nodejs代码中无法识别ISODate
.
But ISODate
is not recognized in my nodejs code.
那么如何通过我的nodejs程序对mongo日期字段进行查询?
So how can I make a query against mongo date fields through my nodejs program?
谢谢
推荐答案
您可以在node.js
;
new
是必须的,因为Date()已用于返回日期字符串.
new
is a must, because Date() is already use to return date string.
ISODate是mongodb中的概念,您可以在mongodb控制台中使用它,但是对于不同的编程语言,它可能会有所不同.
ISODate is concepted in mongodb, you can use it in mongodb console, but it can be different for different programming language.
这篇关于MongoDB + Node.js:如何查询ISODate字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!