社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  MongoDB

选择所有对象在MongoDB字段值的两个日期之间具有日期

hieu nho • 4 年前 • 437 次点击  

从MongoDB获取数据有点困难。我有一个这样的收藏:

    Activities = [
          ... some another activity object item ... ,

          {
              type: "special"
              dates: {
                  begin: ISODate("2019-07-07T17:00:00.000Z"),
                  end: ISODate("2019-07-20T17:00:00.000Z"),
                  note: ""
              },
              status: "pending"
          } ,
          ,
          {
              type: "event"
              dates: {
                times: {
                    from: "12:00",
                    to: "15:00"
                  },
                  begin: ISODate("2019-07-21T17:00:00.000Z"),
                  end: ISODate("2019-08-29T17:00:00.000Z"),
                  note: ""
              },
              status: "pending"
          } ,

          ... some another activity object item ...
      ]

我要获取所有活动数据都有:dates.begin<x(我的参数日期)<dates.end。这就是我的尝试方式:

_Activities.find({
        "dates.end" : {
            $lte : "2019-08-31T17:00:00.000Z"
        },
        "dates.begin" : {
            $gte : "2019-07-15T17:00:00.000Z"
        }
    }, callback);
// return [];


_Activities.find({
        "dates.end" : {
            $lte : "2019-08-30T17:00:00.000Z"
        }
    }, callback);
// return [] too;

我不知道我错在哪里,任何人都有办法帮助我:((谢谢你抽出时间)。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38579
 
437 次点击  
文章 [ 2 ]  |  最新文章 4 年前
Yasser Mas
Reply   •   1 楼
Yasser Mas    4 年前

您可以将日期作为javascript日期对象传递,它将起作用。

dates: {
  end: { $lte: new Date('2019-08-31T17:00:00.000Z') } ,
  begin: { $gte: new Date('2019-07-15T17:00:00.000Z') }
}
Cuong Le Ngoc
Reply   •   2 楼
Cuong Le Ngoc    4 年前

因为你的字段有类型 Date 所以你需要通过 日期 进行比较。类似的事情可能会奏效:

$lte : new Date("2019-08-31T17:00:00.000Z")