I have this example .
db.Wall.runCommand( "text", { search : "See" } );
How to call this from PHP? I can't find the method in MongoCollection
class,
Note I'm running mongo 2.4 dev version.
I tried to use the command method with no luck Collection called Wall
$ret = $db->command( array(
"runCommand" => "Wall",
"text" => array('search' => $text))
);
The output was
Array ( [ok] => 0 [errmsg] => no such cmd: runCommand [bad cmd] => Array ( [runCommand] => Wall [text] => Array ( [search] => See ) ) )
I found the Answer but I need to wait 7 hrs because my reputation is LOW :)
$ret = $db->command( array(
"text" => "Wall",
"search" => $text)
);
This is a more extensive example of Mongo Text Search usage in 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);
$ret = $db->command( array(
"text" => "Wall",
"search" => $text)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.