首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自PHP的MongoDB集合runCommand

来自PHP的MongoDB集合runCommand
EN

Stack Overflow用户
提问于 2013-03-10 01:36:35
回答 2查看 4.7K关注 0票数 2

我有这个example

代码语言:javascript
复制
db.Wall.runCommand( "text", { search : "See" } );

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

注意,我运行的是mongo 2.4 dev版本。

我尝试使用不带幸运集合的命令方法,名为Wall

代码语言:javascript
复制
$ret = $db->command( array(
                        "runCommand" => "Wall",
                        "text" => array('search' => $text))
                    );

输出结果是

代码语言:javascript
复制
Array ( [ok] => 0 [errmsg] => no such cmd: runCommand [bad cmd] => Array ( [runCommand] => Wall [text] => Array ( [search] => See ) ) )

我找到了答案,但我需要等待7个小时,因为我的声誉很低:)

代码语言:javascript
复制
$ret = $db->command( array(
                        "text" => "Wall",
                        "search" => $text)
                    );
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-09 19:08:04

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

代码语言:javascript
复制
<?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);
票数 4
EN

Stack Overflow用户

发布于 2013-03-10 16:59:25

代码语言:javascript
复制
$ret = $db->command( array(
                        "text" => "Wall",
                        "search" => $text)
                    );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15313805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档