在日期时间的月、日、年...上查询 Mongodb

编程入门 行业动态 更新时间:2024-10-24 08:28:36
本文介绍了在日期时间的月、日、年...上查询 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

本文发布于:2023-11-22 20:09:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618834.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   时间   Mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!