我試圖做一些數學函數的3個值從左邊加入收集的值是在正確的集合。Mongo addfields返回集合沒有值
$AllBodies=Invoke-MdbcAggregate @(
# filter bodies with arsenic
@{ '$match' = @{
'name' ='Gru Hypue KS-T d3-31 9 b a'
'materials' = @{ '$elemMatch'[email protected]{ 'material_name'="Arsenic" } }
}}
# list just the name, materials array and FK
@{ '$project' = @{
'system_id'=1;
'name'=1;
'materials'=1;
}}
# unwind the array, duplicates source record
@{ '$unwind' = @{
'path' = '$materials';
'preserveNullAndEmptyArrays' = $false
}}
# now re-filter the for just the material arsenic/
@{ '$match' = @{
'materials.material_name' = 'Arsenic';
'materials.share' = @{ '$gte' = 2.7 }
}}
# sort the records by % arsenic descending
@{ '$sort' = @{
'materials.share' = -1
}}
# left join the systems collection
@{ '$lookup' = @{
'from' = 'systems'
'localField' = 'system_id'
'foreignField' = 'id'
'as' = 'systems'
}}
# add fields to work with later - more dev required
@{ '$addFields' = @{
'x' = '$systems.x'
'y' = '$systems.y'
'z' = '$systems.z'
'systemname' = '$systems.name'
}}
) -Collection $bodies
我想把值提高到頂級文檔的水平,因爲我有抱怨點引用字段的數學函數的麻煩。
在上面的文檔中,我想d = sqr((x1-x2)2+(y1-y2)2+(z1-z2)2)。
我試圖在查詢時要做到這一點,而不是重新處理整個集合,有10萬名的條目(潛在的)
的代碼在PowerShell和.NET驅動的,高興有在.js文件雖然
出認沽如下:...
Name Value
---- -----
_id 59cbf243ef32b7bbe22654b4
name Gru Hypue KS-T d3-31 9 b a
system_id 3288878
materials {material_id, material_name, share}
systems {{ "_id" : ObjectId("59cba528ef32b7bbe28a7640"), "id" : 3288878, "edsm_id" : 2749852, "name" : "Gru Hypue KS-T d3-31", "x" : -4990.84375, "y" : -935.71875, "z" : 13387.15625, "population" : 1000...
y {-935.71875}
systemname {Gru Hypue KS-T d3-31}
z {13387.15625}
x {-4990.84375}
正如你所看到的x,y,z是收藏,而不是值
TIA
請分享一些樣本輸入數據和期望的輸出以及一個正確的問題。你究竟想達到什麼目的? – dnickless
抱歉試圖簡要... – RocketAndy