Searching for value of any field in MongoDB without explicitly naming it

Viewed 92065

I looked through the MongoDB documentation and googled this question but couldn't really find a suitable answer. So, here is what I'm looking for. Assume I have a collection with elements like this:

{
   "foo" : "bar",
   "test" : "test",
   "key" : "value",
}

What I'd like to achieve is find an element by searching in all (maybe except for finitely many ;-) ) fields. In other words: Given a query, I do NOT know in which field the query should be found.

In my thinking something like this

db.things.find({_ANY_ : "bar"}) 

would give me the example element.

Thank you for your help.

7 Answers
Related