如果我在我的架構中有像這樣的嵌入文檔:
location: {
coordinates: [-41.588221, 71.123812],
unitNumber: '4a',
streetAddress: '1 Abc Lane',
<Other location-related data>
}
我要排除的文件和其他使用$nin
位置的基礎上,但我只有unitNumber
和coordinates
,有沒有辦法正確做到這一點。
例如,說我想排除從結果集的位置下面的數組:
locations = [
{coordinates: [-41.2342432, 71.812312], unit: '4a'},
{coordinates: [-40.2242432, 70.212352], unit: '7d'},
{coordinates: [-42.2546432, 72.312312], unit: '10b'},
{coordinates: [-41.2342132, 61.812312], unit: '1z'}
]
有沒有辦法做到這一點給出了上述模式?我不相信使用{location: {$nin: locations}}
會起作用,因爲它要求locations
中的每個對象都要使整個嵌入式文檔符合排除條件。
這工作完美,謝謝!也擔心'$ nin'的表現,所以我很高興這是解決方案:) – jtmarmon 2014-12-08 21:57:14