如何在Mongodb的嵌入式文档中找到一个密钥呢?

时间:2014-05-12 05:28:00

标签: mongodb mongodb-query mongodb-java

{
   _id: "joe",
   name: "Joe Bookreader",
   addresses: [
                {
                  street: "123 Fake Street",
                  city: "Faketon",
                  state: "MA",
                  zip: "12345"
                },
                {
                  street: "1 Some Other Street",
                  city: "Boston",
                  state: "MA",
                  zip: "12345"
                }
              ]
 }

如果在此文档中存在关键街道,如何找到它?

1 个答案:

答案 0 :(得分:2)

您可以使用$ exists operator:

db.yourCollectionName.find( { 'addresses.street': { $exists: true } } );