2013-03-09 27 views
2

我有這個example來自PHP的MongoDB Collection runCommand

db.Wall.runCommand("text", { search : "See" }); 

如何從PHP調用此函數?我找不到MongoCollection類中的方法,

注意我正在運行mongo 2.4 dev版本。

我試圖用命令的方法,沒有所謂的牆

$ret = $db->command(array(
         "runCommand" => "Wall", 
         "text" => array('search' => $text)) 
        ); 

運氣收藏產量爲

Array ([ok] => 0 [errmsg] => no such cmd: runCommand [bad cmd] => Array ([runCommand] => Wall [text] => Array ([search] => See))) 

我找到了答案,但我需要等待7個小時,因爲我的名氣是LOW :)

$ret = $db->command(array(
         "text" => "Wall", 
         "search" => $text) 
        ); 
+0

更廣泛的例子只是發佈答案的回答,您可以勾選自己的答案在2天,這將有助於大家誰涉及到這個問題。考慮到問題的結尾,很難找到答案。 – Sammaye 2013-03-09 21:22:55

回答

4

這是蒙戈文本搜索使用的PHP

<?php 

$m = new MongoClient(); // connect 
$db = $collection = $m->foo; // get the database named "foo" 
$collection = $db->bar; // get the collection "bar" from database named "foo" 

$collection->ensureIndex(
    array(
     'title' => 'text', 
     'desc' => 'text', 
    ), 
    array(
     'name' => 'ExampleTextIndex', 
     'weights' => array(
      'title' => 100, 
      'desc' => 30, 
     ), 
     'timeout' => 60000000 
    ) 
); 

$result = $db->command(
    array(
     'text' => 'bar', //this is the name of the collection where we are searching 
     'search' => 'hotel', //the string to search 
     'limit' => 5, //the number of results, by default is 1000 
     'project' => Array(//the fields to retrieve from db 
      'title' => 1 
     ) 
    ) 
); 

print_r($result); 
0
$ret = $db->command(array(
         "text" => "Wall", 
         "search" => $text) 
        );