MongoDB查找文档的所有属性 [英] MongoDB find on all properties of document
问题描述
如何在mongodb中创建查询以按文档的任何属性进行过滤.
How do I create a query in mongodb to filter by any property of the document.
我有一组对象,如下所示:
I have a collection of objects as follows:
{
"_id" : ...,
"name" : "John",
"city" : "Rio de Janeiro",
"state" : "RJ",
"address" : "Street 1, .... "
}
我的页面上有一个字段,允许用户检索任何列中的专业记录.如果是MYSQL,则在表中找到所有列的名称,并创建一个子句"OR",以搜索用户输入的值"LIKE".
I have on my page a field that allows a user to retrieve pro records in any column. If it was MYSQL I find the names of all the columns in the table and create a clause 'OR' searching for 'LIKE' the value entered by the user.
是否有任何简单的方法可以使用mongodb进行操作,而不必搜索文档中所有现有的属性?
Is there any easy way to do this with mongodb, without having to search for all the existing properties in the document?
推荐答案
At this time, I don't believe this is supported: https://jira.mongodb.org/browse/SERVER-1248
或者,您可以将Elasticsearch与MongoDB结合使用:如何将Elasticsearch与MongoDB结合使用? /a>.
Alternatively, you could use Elasticsearch with MongoDB: How to use Elasticsearch with MongoDB?.
设置完毕后,您可以轻松地运行匹配查询来搜索所有字段:{"query":{'match':{'_all':your_query}}}
Once you set it up, you could easily run a match query to search all fields: {"query":{'match':{'_all':your_query}}}
这篇关于MongoDB查找文档的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!