Linux MongoDB仅返回在最近一小时/24小时内更新的字段

Linux MongoDB仅返回在最近一小时/24小时内更新的字段,linux,mongodb,database,Linux,Mongodb,Database,我在这方面找了很多线索,但似乎都不管用 我得到的最接近的表格如下: db.<collection>.find({ $where: function () { return Date.now() - this._id.generation_time() < (24 * 60 * 60 * 1000) } }) 我想知道是否有办法使用“时间戳”与日期进行比较。现在()…尝试了一些已经不起作用的事情。。。想知道是否有古鲁能伸出援手 谢谢 不要使用\u id的(这将失败,因为它不

我在这方面找了很多线索,但似乎都不管用

我得到的最接近的表格如下:

db.<collection>.find({ $where: function () { return Date.now() - this._id.generation_time() < (24 * 60 * 60 * 1000)  }  })
我想知道是否有办法使用“时间戳”与日期进行比较。现在()…尝试了一些已经不起作用的事情。。。想知道是否有古鲁能伸出援手


谢谢

不要使用
\u id
(这将失败,因为它不是有效的),而是通过创建一个保存24小时前的日期对象的变量并在查询中使用操作符,在
“created\u on”
日期字段上执行日期范围查询:

var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
db.collection.find({ "created_on": { "$gte": yesterday } });

你好!在test.js中尝试了脚本,然后执行了mongo localhost:27017/**test.js。它只有一条消息:正在连接到:。能否尝试在mongo shell中针对实际集合名称运行查询?
  {
        "_id" : "edge:Package-1e63f289-022e-4678-b806-72244277db54",
        "data_1442611395145" : {
                "ulid" : ObjectId("55fc4883e1382301adfde5dd"),
                "etlp" : "AMBER",
                "api" : {
                        "indicators" : [
                                {
                                        "idref" : "CISCP:indicator-161e129e-3647-48fb-ab4c-ff1bea0e08a9"
                                }
                        ],
                        "timestamp" : "2015-09-18T17:23:15.145333+00:00",
                        "version" : "1.1.1",
                        "id" : "edge:Package-1e63f289-022e-4678-b806-72244277db54",
                        "stix_header" : {
                                "handling" : [
                                        {
                                                "controlled_structure" : "../../../../descendant-or-self::node()",
                                                "marking_structures" : [
                                                        {
                                                           "color" : "AMBER",
                                                           "xsi:type" : "tlpMarking:TLPMarkingStructureType"
                                                        },
                                                        {
                                                           "xsi:type" : "simpleMarking:SimpleMarkingStructureType",
                                                           "statement" : "FOUO"
                                                        }
                                                ]
                                        }
                                ]
                        }
                },
                "hash" : ".cdb111212d2706be3dcb58b896cd1629993fa951",
                "idns" : "http://soltra.com/",
                "etou" : [ ],
                "esms" : [
                        "FOUO"
                ],
                "edges" : {
                        "CISCP:indicator-161e129e-3647-48fb-ab4c-ff1bea0e08a9" : "ind"
                },
                "summary" : {
                        "intent" : [ ]
                }
        },
        "created_on" : ISODate("2015-09-18T17:23:15.490Z"),
        "created_by_username" : "admin",
        "data" : {
                "ulid" : ObjectId("55fc4883e1382301adfde5dd"),
                "etlp" : "AMBER",
                "api" : {
                        "indicators" : [
                                {
                                        "idref" : "CISCP:indicator-161e129e-3647-48fb-ab4c-ff1bea0e08a9"
                                }
                        ],
                        "timestamp" : "2015-09-18T17:23:15.145333+00:00",
                        "version" : "1.1.1",
                        "id" : "edge:Package-1e63f289-022e-4678-b806-72244277db54",
                        "stix_header" : {
                                "handling" : [
                                        {
                                                "controlled_structure" : "../../../../descendant-or-self::node()",
                                                "marking_structures" : [
                                                        {
                                                           "color" : "AMBER",
                                                           "xsi:type" : "tlpMarking:TLPMarkingStructureType"
                                                        },
                                                        {
                                                           "xsi:type" : "simpleMarking:SimpleMarkingStructureType",
                                                           "statement" : "FOUO"
                                                        }
                                                ]
                                        }
                                ]
                        }
                },
                "hash" : "c45722264e9d129154c2b01ad9e0709e836e2fe8",
                "idns" : "http://soltra.com/",
                "etou" : [ ],
                "esms" : [
                        "FOUO"
                ],
                "edges" : {
                        "CISCP:indicator-161e129e-3647-48fb-ab4c-ff1bea0e08a9" : "ind"
                },
                "summary" : {
                        "intent" : [ ]
                }
        },
        "cv" : "1442611395145",
        "versions" : [
                "1442611395145"
        ],
        "created_by" : ObjectId("559450775bf8065a2d6476c1"),
        "tg" : [ ],
        "type" : "pkg",
        "created_by_organization" : null
}
{
        "_id" : "CISCP:indicator-161e129e-3647-48fb-ab4c-ff1bea0e08a9",
        "created_on" : ISODate("2015-09-18T17:23:15.491Z"),}
var yesterday = new Date(new Date().getTime() - (24 * 60 * 60 * 1000));
db.collection.find({ "created_on": { "$gte": yesterday } });