Using find() to search for nested keys in MongoDB Using find() to search for nested keys in MongoDB mongodb mongodb

Using find() to search for nested keys in MongoDB


You have to use dot notation to get what you're looking for. It would look like:

db.collections.find({"headers.server":"gws"})

In your query, what you're asking for is documents where headers is an object that looks like {server: "gws"}, so that only work if you know what the entire subdocument is.