我有MongoDB中的數據集,這是一個線我的數據的一個示例:查詢當陣列大小被存儲在一個變量
{ "conversionDate": "2016-08-01",
"timeLagInDaysHistogram": 0,
"pathLengthInInteractionsHistogram": 4,
"campaignPath": [
{"campaignName": "name1", "source": "sr1", "medium": "md1", "click": "0"},
{"campaignName": "name2", "source": "sr1", "medium": "md1", "click": "0"},
{"campaignName": "name1", "source": "sr2", "medium": "md2", "click": "1"},
{"campaignName": "name3", "source": "sr1", "medium": "md3", "click": "1"}
],
"totalTransactions": 1,
"totalValue": 37.0,
"avgCartValue": 37.0
}
(長度的campaignPath不是恆定的,所以每行可以有不同數量的元素。
而且我要找到匹配campaignPath的最後一個元素「來源= SR1」 元素。
我知道我不能用som進行查詢ething像
db.paths.find(
{
'campaignPath.-1.source': "sr1"
}
)
但是,因爲我有 「pathLengthInInteractionsHistogram」 存儲等於campaignPath lenght的長度,我不能這樣做:
db.paths.find(
{
'campaignPath.$pathLengthInInteractionsHistogram.source': "sr1"
}
)
@JohnnyHK我想整個文件,因爲我需要的日期等信息。 –