Mongodb日期范围查询不返回任何结果

时间:2016-08-01 01:17:40

标签: mongodb

我对MongoChef中的以下查询没有任何乐趣 - 它不返回任何结果。如果我在mLab中运行相同的查询,那么它可以工作。我想知道它可能出现什么问题。

$match : {
"account_balances_date": {
    "$gte": {
        "$date": "2016-04-01T00:00:00.000Z"
    },
    "$lte": {
        "$date": "2016-08-01T00:00:00.000Z"
    }
}
}

这是一个示例文档,其中account_balances_date位于查询范围内。感谢

{
"_id": {
    "$oid": "5799ba3ff36d280883999c06"
},
"object_class": "Account Balances",
"object_category": "Application",
"object_type": "Report on Balances",
"object_origin": "Sage One",
"object_origin_category": "Bookkeeping",
"object_creation_date": {
    "$date": "2016-05-15T22:49:35.665Z"
},
"party_uuid": "phildominickcompany",
"connection_uuid": "5738fc661a21db15b5c45b49",
"account_balances_date": {
    "$date": "2016-04-30T10:00:00.000Z"
},
"account_balances": [
    {
        "account_identifier": "1100",
        "account_name": "Trade Debtors",
        "account_category": "Current Assets",
        "account_type": "Debtors",
        "account_currency": null,
        "account_value": 103800,
        "account_value_type": "debit"
    },
    {
        "account_identifier": "2100",
        "account_name": "Trade Creditors",
        "account_category": "Current Assets",
        "account_type": "Creditors",
        "account_currency": null,
        "account_value": 53700,
        "account_value_type": "credit"
    },
    {
        "account_identifier": "2200",
        "account_name": "VAT on Sales",
        "account_category": "Current Liabilities",
        "account_type": "Tax",
        "account_currency": null,
        "account_value": 17300.01,
        "account_value_type": "credit"
    },
    {
        "account_identifier": "2201",
        "account_name": "VAT on Purchases",
        "account_category": "Current Liabilities",
        "account_type": "Tax",
        "account_currency": null,
        "account_value": 8950,
        "account_value_type": "debit"
    },
    {
        "account_identifier": "3260",
        "account_name": "Drawings - equity",
        "account_category": "Equity",
        "account_type": null,
        "account_currency": null,
        "account_value": 65000,
        "account_value_type": "debit"
    },
    {
        "account_identifier": "4000",
        "account_name": "Sales Type A",
        "account_category": "Revenue",
        "account_type": "Sales",
        "account_currency": null,
        "account_value": 16666.67,
        "account_value_type": "credit"
    },
    {
        "account_identifier": "5000",
        "account_name": "Cost of sales - goods",
        "account_category": "Expense",
        "account_type": "Sales",
        "account_currency": null,
        "account_value": 2500,
        "account_value_type": "debit"
    },
    {
        "account_identifier": "5010",
        "account_name": "Cost of sales - materials",
        "account_category": "Expense",
        "account_type": "Sales",
        "account_currency": null,
        "account_value": 10000,
        "account_value_type": "debit"
    }
],
"debtors_and_creditors": []
}

1 个答案:

答案 0 :(得分:1)

如[{3}}所述,运算符$dateJSON格式扩展为存储date对象。运行查询时,可能无法在所有GUI工具中识别它。相反,您可能希望改为使用ISODate("2016-04-01T00:00:00.000Z")

$match: {
    "account_balances_date": {
        "$gte": ISODate("2016-04-01T00:00:00.000Z"),
        "$lte": ISODate("2016-08-01T00:00:00.000Z")
    }
}
相关问题