我試圖運行這個簡單的例子來試試例子(MongoDB的網站找到)如何在蒙戈2.4沒有收集文本索引的MongoDB
<?php
$m = new Mongo();
$d = $m->demo;
$c = $d->planets;
$c->insert(array("name" => "Mercury", "desc" => "Mercury is the smallest and closest to the Sun"));
$c->insert(array("name" => "Venus", "desc" => "Venus is the second planet from the Sun, orbiting it every 224.7 Earth days."));
$c->insert(array("name" => "Earth", "desc" => "Earth is the the densest of the eight planets in the Solar System."));
$c->insert(array("name" => "Mars", "desc" => "Mars is named after the Roman god of war."));
$c->ensureIndex(array('desc' => 'text'));
$r = $d->command(array("text" => "planets", 'search' => "sun"));
print_r($r);
?>
使用TEXTSEARCH feauture但我得到這個錯誤:Array ([ok] => 0 [errmsg] => no text index for: demo.planets)
我不明白爲什麼,因爲我已經在這行定義的文本索引:
$c->ensureIndex(array('desc' => 'text'));
和TEXTSEARCH啓用。
謝謝你的幫助!
作爲MongoDB中的2.6.x的,文本搜索默認情況下啓用。在MongoDB 2.4.x上,你需要啓用它,如上所示 – bjori