Question

{
   _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"
                }
              ]
 }

How to find the key street if it exists in this document?

Was it helpful?

Solution

You can use $exists operator:

db.yourCollectionName.find( { 'addresses.street': { $exists: true } } );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top