Can you query MongoDB for any properties with a given value?

I am starting to play with MongoDB, and I am wondering if it is possible to query the data store for any property with a specific value.

So, instead of:

db.foo.find({'color':'red'})

I am looking to do something like:

db.foo.find({'%':'red'})

Is it possible? Is there any syntax for substituting a property slot? I tried using regex, but that gave me an error.

+3
source share
1 answer

You can request property names (key names) with map reduction. See Here: MongoDB Get the names of all keys in a collection

Maybe you can write a map reduction function that asks for a combination of the property name and its value with JavaScript?

But why do you need this?

+2

Source: https://habr.com/ru/post/1735287/


All Articles