S
S
Sarkis Arutiunian2016-07-11 02:09:25
JavaScript
Sarkis Arutiunian, 2016-07-11 02:09:25

Mongodb (Mongoose).find() how to search for non-exact match?

Let's say I need to find in the database all the objects whose property "string" contains part of the desired value, for example, we are looking for all objects whose property "string" is equal to or contains the value of the search string.
Let's say we have the desired phrase:
let value = "serg"
and now I need to find all the objects in the "Users" table whose name property contains or is equal to this string:
Users.find({name: value});
but with such a search, there is a strict comparison, there are options to achieve something similar ~name.indexof(value)and if the condition is true, then the object will be included in the output array?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2016-07-11
@sarkis-tlt

googled for you

L
lega, 2016-07-11
@lega

1) If the number of search words is not large, then you can make an array in the document and store it there.
2) Use a text
index it is a complete enumeration of all documents.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question