'How to access array of object in MongoDB

 { _id: ObjectId("6203ad7eee9d346bd2681d54"),
      
      OrderID: 'QfoO-124Q?458BW',
      Status: 'Successful',
      
      CustomerInfo:
 
       [ { 'first-name': 'Gillespie' },
         { 'last-name': 'Lozano' },
         { email: '[email protected]' },
         { 'phone-number': 8863744 },
         { address: '39 Park Road, LINCOLN, LN84 2MG' }
       ],

      PurchaseDate: '20/02/2020',
      }

I want to query one of the objects inside the array of CustomerInfo for example how to get the value of the key email using the keys CartItems and email.? without outputting the whole document?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source