MongoDB过滤器查询没有返回我想要的结果

时间:2017-11-06 09:32:17

标签: mongodb mongodb-query

我对一个简单的MongoDB查询感到困惑,我无法弄清楚问题出在哪里。我有这样的集合:

{
"_id" : NumberLong(1939026454),
"username" : "5144269288",
"_type" : 1,
"group_id" : 416,
"user_id" : NumberLong(426661),
"credit_used" : 0.0,
"retry_count" : 1,
"successful" : true,
"type_details" : {
    "in_bytes" : 0,
    "sub_service_qos" : "",
    "sub_service_name" : "rating-group-103",
    "out_bytes" : 0,
    "sub_service_charging" : "FreeIPTV",
    "remote_ip" : ""
},
"logout_time" : ISODate("2017-11-06T07:16:09.000Z"),
"before_credit" : 4560.2962,
"ras_id" : 18,
"caller_id" : "",
"isp_id" : 0,
"duration" : NumberLong(14500),
"details" : {
    "connect_info" : "rate-group=103",
    "sub_service" : "rating-group-103",
    "diameter_request_type" : "initial"
},
"unique_id_value" : "918098048;falcon;Dehghan01000000001415716f9a113697;529;falcon-02b4e8a7__103",
"charge_rule_details" : [ 
    {
        "start_in_bytes" : 0,
        "charge_rule_id" : 3682,
        "start_out_bytes" : 0,
        "stop_time" : ISODate("2017-11-06T07:16:09.000Z"),
        "stop_out_bytes" : 0,
        "start_time" : ISODate("2017-11-06T03:14:29.000Z"),
        "charge_rule_desc" : "rating-group-103",
        "stop_in_bytes" : 0
    }
],
"unique_id" : "acct_session_id",
"login_time" : ISODate("2017-11-06T03:14:29.000Z")
}

我需要过滤login_time介于两个给定日期之间的文档,type_details.sub_service_name是一些字符串。

我试过了:

db.getCollection('connection_log_partial_data').find({
"type_details" : {"sub_service_name": "rating-group-103"},
"login_time": {
    "$gt": ISODate("2016-11-06T03:14:29.000Z"),
    "$lt": ISODate("2017-11-06T03:14:29.000Z")
}
});

但它会获取0条记录。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您的查询应该是:

foreach line [split $inputdata "\n"] {
    if {$line eq ""} continue
    set bits [regexp -all -inline {\([^()]+\)} $line]
    set list([incr idx]) {}
    foreach substr $bits {
        lappend list($idx) [scan $substr "(%d,%d)"]
        # In *very* old Tcl you'd need this:
        #    scan $substr "(%d,%d)" a b
        #    lappend list($idx) [list $a $b]
    }
}