簡體   English   中英

來自PHP的MongoDB集合runCommand

[英]MongoDB Collection runCommand from PHP

我有這個例子

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);
$ret = $db->command( array(
                        "text" => "Wall",
                        "search" => $text)
                    );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM