我是mongo的新手,需要帮助查找在请求的时间创建的数据库条目。在我的例子中有很多嵌入字段,我不理解请求的语法:
{
"_id": "54e1a045e4b03f5930293da6",
"_version": 31867,
"_transId": "4ae4d0e6-d3df-4a24-9621-1cdb7f12362f-10489329",
"accountBalances": {
"BALANCE": {
"thresholds": {
},
"quotas": "ROLLOVER_QUOTA": {
"thresholds": {
},
"quotaCode": "ROLLOVER_QUOTA",
"credits": {
"_1HVa0dJoEeSUwbM1-xYKvg": {
"startDate": ISODate("2015-03-24T21:00:00Z"),
"creditAmount": "547194099151",
"endDate": ISODate("2020-03-24T21:00:00Z"),
"started": true,
"debits": {
"consolidated": {
"creationDate": ISODate("2015-04-17T18:00:01.469Z"),
"debitAmount": "547194090291",
"debitId": "consolidated"
}
},
"creditId": "_1HVa0dJoEeSUwbM1-xYKvg"
}
}
}
}
}
我需要搜索具有借记创建日期$gte:ISODate("2015-03-16T00:00:00.000Z"), $lte:ISODate("2015-03-16T04:00:00.000Z"
答案 0 :(得分:0)
您可以使用 dot notation 访问嵌入文档的字段:
db.collection.find(
{
"accountBalances.BALANCE.quotas.ROLLOVER_QUOTA.credits._1HVa0dJoEeSUwbM1-xYKvg.debits.creationDate": {
"$gte": ISODate("2015-03-16T00:00:00.000Z"),
"$lte": ISODate("2015-03-16T04:00:00.000Z")
}
}
);