0

In the mongo shell, I have inserted the following documents into the guests collection:

{
    "name": "Jackson",
    "title": "Sir",
    "preferences": [
        {
            "Restaurant": "LobsterHouse"
        },
        {
            "Room": "333"
        },
            {
            "Transportation": [
                "Limo",
                "Town Car",
                "Taxi"
            ]
        }
    ]
},
{
    "name": "Peterson",
    "title": "Mr",
    "preferences": [
        {"Restaurant": "Lobster House"},
        {"Room": "321"},
        {"Transportation": "Town Car"}
    ]
},
{
    "name": "Hodgson",
    "title": "Mrs",
    "preferences": [
        {"Restaurant": "The Sushi Bar"},
        {"Room": "180"},
        {"Transportation": "Taxi"}
    ]
}

I want to be able to search this two ways,

1) Get all guests where inside preferences, Transportation equals "Taxi"

I have tried: db.guests.preferences.find({"Transportation":"Taxi"})

also I have tried the following find method and only get back "Hodgson"

db.guests.find({preferences: {"Transportation":"Taxi"}})

Which I can't understand why it doesn't go inside of "Jackson" and find the value in the array of "Transportation" items

Any help would be much appreciated

Community
  • 1
  • 1
Eric Bishard
  • 5,201
  • 7
  • 51
  • 75

0 Answers0