R
R
Relike2016-02-12 19:22:11
PHP
Relike, 2016-02-12 19:22:11

Fulltext mongodb search via php array driver?

Is it possible to perform a full-text search on an array of strings. More precisely, there is a document of the form:

{
    _id: "sfgsdfgsd",
    strings: [
        "string 1 abc",
        "string 2 def",
        "string 3 ghi"
    ]
}

and it is necessary to determine whether there is an entry "def" in this document in the strings array. Does anyone know how to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
karetsky, 2016-02-14
@karetsky

PHP example:

$q='def';
$collection=$db->your_collection;
$data=$collection->find(array('strings'=>new MongoRegex("/$q/i") ));
And _id cannot be a string, it is always new MongoId();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question