简体   繁体   English

MongoDB在锂中运行命令

[英]MongoDB running command in lithium

I'm trying to run a full text search against some data that is stored in mongoDb using Lithium. 我正在尝试使用Lithium对存储在mongoDb中的某些数据进行全文搜索。

Here is how I am trying to do it in my controller: 以下是我在控制器中尝试执行此操作的方法:

$mongodb = Connections::get('default')->connection;
$results = Page::connection()->connection->command(array("text" => "Page", 'search' => "term" ));

I've also tried: 我也尝试过:

$results = Page::connection()->connection->command(array("text" => "Page", 'search' => "term" ));

However, both of these return: Fatal error: Call to a member function command() on a non-object 但是,这两个都返回:致命错误:在非对象上调用成员函数command()

What am I doing wrong? 我究竟做错了什么?

EDIT: 编辑:

I should add that a simple query on Page is working just fine. 我应该补充一点,关于Page的简单查询工作得很好。 For instance: 例如:

$results = Page::find('all');

Does return an array with all of the documents in the pages collection like I would expect it to. 返回一个包含页面集合中所有文档的数组,就像我期望的那样。

UPDATE 2: 更新2:

I was running all of this from WAMP server. 我从WAMP服务器运行所有这些。 I tried today running it from a linux server, but still got the same exact error. 我今天尝试从Linux服务器运行它,但仍然得到了同样的错误。 I am really stumped by this and could use some help. 我真的很难过这个并且可以使用一些帮助。 Anyone have any ideas? 有人有想法么?

here is the Page model as it sits now: 这是现在的Page模型:

<?php
namespace app\models;

use lithium\data\Connections; //added during debugging
use lithium\data\source\MongoDb; //added during debuging

class Page extends \lithium\data\Model {

}
?>

Here is my connection: 这是我的联系:

 Connections::add('default', array(
        'type' => 'MongoDb',
        'host' => '192.168.48.128',
        'database' => 'my_collection'
 ));

I'm doing it this way: 我是这样做的:

$plugins = Plugins::connection()->connection->command([
    'text' => 'plugins',
     'search' => $this->request->query['q']
]);
return compact('plugins');

so I'd recommend checking your configuration - is your model returning other data normally? 所以我建议检查你的配置 - 你的模型是否正常返回其他数据? Is the connection configuration correct? 连接配置是否正确?

Got help to figure it out... posting here for others to reference. 得到帮助弄清楚...发布在这里供其他人参考。

proper way of calling it is: 适当的方式是:

$conn = Model::connection();
$db = $conn->selectDB('db');
$result = $db->command(array(...

Works perfectly when done this way. 这样做时效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM