vaheeds
vaheeds

Reputation: 2913

MongoDB filter query doesn't return my desired result

I am getting confused with a simple MongoDB query that I can't figure it out where the problem is. I have a collection like this:

{
"_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")
}

I need to filter documents that login_time is between two given dates and type_details.sub_service_name is some string.

I tried this:

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")
}
});

but it fetches 0 records. Any suggestions?

Upvotes: 0

Views: 95

Answers (1)

Elmer Dantas
Elmer Dantas

Reputation: 4859

your query should be something like:

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

Upvotes: 1

Related Questions