如何查詢嵌套對象?當使用嵌套對象表示法查詢MongoDB時,我遇到了一個問題:db.messages.find( { headers : { From: "[email protected]" } } ).
count()0db.messages.find( { 'headers.From': "[email protected]" } ).count()5我看不出我做錯了什么。我期望嵌套對象表示法返回與點表示法查詢相同的結果。我哪里錯了?
3 回答

Helenr
TA貢獻1780條經驗 獲得超4個贊
db.messages.find( { headers : { From: "[email protected]" } } )
headers
等號 { From: ... }
db.messages.find( { 'headers.From': "[email protected]" } )
headers.From
headers
.

慕田峪9158850
TA貢獻1794條經驗 獲得超8個贊
company
'ABC123'
address
'123 Street'
db.inventory.find( { producer: { company: 'ABC123', address: '123 Street' }});
- 3 回答
- 0 關注
- 756 瀏覽
添加回答
舉報
0/150
提交
取消