MongoDB find all document properties

How to create a query in mongodb to filter by any document property.

I have a set of objects like this:

{
  "_id" : ...,
  "name" : "John",
  "city" : "Rio de Janeiro",
  "state" : "RJ",
  "address" : "Street 1, .... "
}

      

I have a field on my page that allows the user to fetch pro records in any column. If it is MYSQL, I find the names of all the columns in the table and create an "OR" clause to find the "LIKE" of the value entered by the user.

Is there any easy way to do this with mongodb, without having to search for all existing properties in the document?

+3


source to share


1 answer


I do not currently believe this is supported: https://jira.mongodb.org/browse/SERVER-1248

Alternatively, you can use Elasticsearch with MongoDB: How to use Elasticsearch with MongoDB? ...



Once configured, you can easily run a match query to search across all fields: {"query":{'match':{'_all':your_query}}}

+3


source







All Articles