How to query nested objects?

前端 未结 3 2153
野性不改
野性不改 2020-11-22 01:43

I have a problem when querying mongoDB with nested objects notation:

db.messages.find( { headers : { From: \"reservations@marriott.com\" } } ).count()
0
db.m         


        
3条回答
  •  终归单人心
    2020-11-22 02:33

    db.messages.find( { headers : { From: "reservations@marriott.com" } } )

    This queries for documents where headers equals { From: ... }, i.e. contains no other fields.


    db.messages.find( { 'headers.From': "reservations@marriott.com" } )

    This only looks at the headers.From field, not affected by other fields contained in, or missing from, headers.


    Dot-notation docs

提交回复
热议问题