I have field message
in a collection messages
, for example:
[
{
_id: "chrYMAqT8meXpqdrC",
message: "Hello world. This is mongo"
},
{
_id: "rKu5gf5zL6NaSvZ5Q",
message: "Hello. This is mongo world"
},
{
_id: "rKu5gf5zL6NaSvZ5Q",
message: "world. This is mongo Hello"
}
]
I want to search for messages where the message
field contains /Hello world/ig
or where the message
field contains the words Hello
and word
. And most importantly - the words must be found in the order of the input string, so the last element in the collection must not be found, but the first two must. I know how to find by matching with regex, but in the second case i don't understand how to do it