2016-08-01 137 views
0

我對MongoChef中的下列查詢沒有任何興趣 - 它不返回任何結果。如果我在mLab中運行相同的查詢,那麼它可以工作。我想知道它有什麼問題。Mongodb日期範圍查詢返回無結果

$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

如上所述here,操作者$date是擴展JSON格式存儲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") 
    } 
} 
+0

真棒@yaoxing謝謝你,完美 –