admin管理员组文章数量:1287511
So I have this field called task_time
stored as string in Mongodb in 'YYYY-MM-DD'
format (eg. '2012-12-21').
Now I need to query this collection to get the data whose task_time
is within a given time interval.
The time interval is given as a pair of strings that represent start time and end time in 'YYYY-MM-DD hh:mm:ss'
format (eg. '2015-12-21 16:00:00').
Is there any way to do this directly in Mongo query without bringing this task to my javascript code?
So I have this field called task_time
stored as string in Mongodb in 'YYYY-MM-DD'
format (eg. '2012-12-21').
Now I need to query this collection to get the data whose task_time
is within a given time interval.
The time interval is given as a pair of strings that represent start time and end time in 'YYYY-MM-DD hh:mm:ss'
format (eg. '2015-12-21 16:00:00').
Is there any way to do this directly in Mongo query without bringing this task to my javascript code?
Share Improve this question asked Jan 5, 2016 at 8:37 delsindelsin 3234 silver badges12 bronze badges 01 Answer
Reset to default 12As I know $gte
and $lt
can work with strings too. The same in mongoose after this issue
items.find({
task_time: {
$gte: "2015-12-21 12:00:00",
$lt: "2015-12-21 16:00:00"
}
})
本文标签: javascriptHow to handle date stored as string in MongodbStack Overflow
版权声明:本文标题:javascript - How to handle date stored as string in Mongodb? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741309420a2371564.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论