Jeff86
Jeff86

Reputation: 144

Text command will be removed > should use $text query instead

I've just set up MongoDB with last release of every components:

I made a quick test to check if my DB is ok and I can retrieve my data using full text search:

$m = new MongoClient();
$db = $m->mytestdb;

$result = $db->command(
    array(
        'text' => 'items',
        'search' => 'something',
        'limit' => 50,
    )
);

Everything is OK but when I see MongoDB logs there is one strange message I can't find any answers on the web:

[conn1] The text command will be removed in a future release. Use the $text query operator instead.

As I'm just starting to work on it it's kinda freaking me to know that the Full Text search I'm just using will be deprecated.

Even the official doc is using that code (see example #4).

So what should I use instead of my code? I'm afraid that if I use this code someday during an apt-get update & upgrade all my code will drop down.

Upvotes: 1

Views: 223

Answers (2)

Jeff86
Jeff86

Reputation: 144

I found out with the new $text from 2.6, here is how to do the same request as before with command:

$m = new MongoClient();
$db = $m->mytestdb;
$collection = $db->items;

$cursor = $collection->find(
    array(
        '$text' => array('$search' => 'something to search')
    ),
    array (
        'score' => array('$meta' => "textScore")
    )
);

Upvotes: 1

Henry
Henry

Reputation: 53

It seem's like they are rolling out $text in 2.6, and deprecating the text search feature.

you can reference more information of $text here.

http://docs.mongodb.org/manual/reference/operator/query/text/#op._S_text

Upvotes: 0

Related Questions