Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自PHP的MongoDB集合runCommand_Php_Mongodb - Fatal编程技术网

来自PHP的MongoDB集合runCommand

来自PHP的MongoDB集合runCommand,php,mongodb,Php,Mongodb,我有这个 如何从PHP调用它?我在MongoCollection类中找不到该方法 注意,我正在运行Mongo2.4dev版本 我尝试使用命令方法,但没有名为Wall的幸运集合 $ret = $db->command( array( "runCommand" => "Wall", "text" => array('search' => $text))

我有这个

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

注意,我正在运行Mongo2.4dev版本

我尝试使用命令方法,但没有名为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文本搜索的一个更广泛的示例

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

这是在PHP中使用Mongo文本搜索的一个更广泛的示例

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

只需将答案作为答案发布,你可以在2天内勾选你自己的答案,这将帮助每个回答这个问题的人。把答案放在问题的末尾会让你更难找到答案。只要把答案作为答案贴出来,你可以在两天内勾选你自己的答案,这将帮助每个回答这个问题的人。把问题放在末尾会使答案更难找到。
<?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);