0

I was trying to get all documents whose place_id is equal to 4 using the query below but I'm getting this error:

SyntaxError: missing : after property id @(shell):1:23.

Did I type something wrong? The query I'm using is:

db.sidebar.find({ result.place_id: 4 });

And this is an example document:

{  
    "_id":ObjectId("5aebb473e8e191cb74ef8877"),
    "result":{  
        "place_id":4,
        "formatted_address":"589 Doyle Divide",
        "geometry":{  
            "location":{  
                "lat":"-18.8806",
                "lng":"177.1928"
            }
        },
        "international_phone_number":"(571) 978-2039 x11427",
        "name":"Walker Inc",
        "opening_hours":{  
            "weekday_text":[  
                "Monday: 01:00 PM – 03:30 PM",
                "Tuesday: 01:00 PM – 03:30 PM",
                "Wednesday: 01:00 PM – 03:30 PM",
                "Thursday: 01:00 PM – 03:30 PM",
                "Friday: 01:00 PM – 03:30 PM",
                "Saturday: 01:00 PM – 03:30 PM",
                "Sunday: 01:00 PM – 03:30 PM"
            ]
        },
        "url":"https://maps.google.com/?cid=4",
        "website":"http://www.Stracke - Wintheiser.com/"
    }
}
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
tausabao
  • 247
  • 1
  • 3
  • 11

1 Answers1

0

You need to use dot notation to access the fields of an embedded document. That means you need to add quotes around those fields:

db.sidebar.find({ "result.place_id": 4 });

You might think this should also work:

db.sidebar.find({ result: { place_id: 4 });

But while the former is asking MongoDB to look for a document with a place_id field whose value is 4, inside a field result (which might contain other fields as well), the later will look for an exact match of the subdocument, that is, it will match only documents whose result field is exactly { place_id: 4 }, without any other field in it.

Danziger
  • 19,628
  • 4
  • 53
  • 83