来自PHP的MongoDB集合runCommand

我有这个example.

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

如何从PHP调用它?我在MongoCollection类中找不到该方法,

注意我正在运行mongo 2.4 dev版本.

我试图使用没有运气的名为Wall的命令方法

$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个小时:)

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

解决方法:

这是PHP中Mongo Text Search用法的更广泛示例

<?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);

相关文章

MongoTemplate 是Spring Data MongoDB 中的一个核心类,为 S...
笔者今天要分享的是一个项目重构过程中如何将数据库选型由原...
mongodb/mongoTemplate.upsert批量插入更新数据的实现
进入官网下载官网安装点击next勾选同意,点击next点击custom...
头歌 MongoDB实验——数据库基本操作
期末考试复习总结