I need to query MongoDB on the number of the fields: name, phone, email.
And the query should support "like"
syntax: '%s%'
What is the better way to perform it:
- Query on number of fields with $or
- Create array field with values of the above fields and multikey index on this field
An example collection contains the following documents
{
name: "Evgeny3345",
phone: "4678946",
email: "trial@stack.com"
},
{
name: "bug",
phone: "84567521",
email: "bug@stack.com"
},
{
name: "bug2",
phone: "84567521",
email: "deny@stack.com"
}
When I find all documents with name or phone or email containing "eny"
, this should return documents 1 and 3.