本文介绍了在日期时间的月、日、年...上查询 Mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 mongodb 并以这种方式将日期时间存储在我的数据库中
I'm using mongodb and I store datetime in my database in this way
对于我存储的日期17-11-2011 18:00":
for a date "17-11-2011 18:00" I store:
date = datetime.datetime(2011, 11, 17, 18, 0) db.mydatabase.mycollection.insert({"date" : date})我想做这样的请求
month = 11 db.mydatabase.mycollection.find({"date.month" : month})或
day = 17 db.mydatabase.mycollection.find({"date.day" : day})有人知道怎么做这个查询吗?
anyone knows how to do this query?
推荐答案日期以其时间戳格式存储.如果您想要属于特定月份的所有内容,请查询月份的开始和结束时间.
Dates are stored in their timestamp format. If you want everything that belongs to a specific month, query for the start and the end of the month.
var start = new Date(2010, 11, 1); var end = new Date(2010, 11, 30); db.posts.find({created_on: {$gte: start, $lt: end}}); //taken from cookbook.mongodb/patterns/date_range/更多推荐
在日期时间的月、日、年...上查询 Mongodb
发布评论