我有一个名为“公司”的mongo集合,如下所示:
{
"_id" : ObjectId("..."),
"name" : "company_1",
"active" : false,
"projects" : [
{
"_id" : ObjectId("..."),
"name" : "Prj_1",
...
},
{
"_id" : ObjectId("..."),
"name" : "Prj_2" ,
...
}
],
"rating" : 0,
...
}
...
我使用Kohana 3.2作为我的框架和MangoDb库。
我想写一个函数来检索所有项目并为用户列出它们(Retrieving a Subset of Fields)。
这是我的公司型号:
<?php
class Model_Company extends Mango {
protected $_db = 'default';
protected $_collection = 'companies';
protected $_fields = array(
'name' => array(
'type' => 'string',
'required' => TRUE,
),
'active' => array(
'type' => 'boolean',
),
'rating' => array(
'type' => 'float',
),
'projects' => array(
'type' => 'has_many',
),
...
...
);
public function data_list($from = 0, $limit = 10, $sort = NULL)
{
return Mango::factory('company')->load(array( 'limit' => $limit, 'sort' => $sort, 'skip' => $from ));
}
}
这是嵌入式项目模型:
<?php
class Model_Project extends Mango {
protected $_embedded = TRUE;
protected $_db = 'default';
//protected $_collection = 'projects';
protected $_fields = array(
'_id' => array(
'type' => 'MongoId'
),
'name' => array(
'type' => 'string',
'required' => TRUE,
),
...
...
);
public function data_list($from = 0, $limit = 10, $sort = NULL)
{
return Mango::factory('company')->load(array(
'limit' => $limit,
'sort' => $sort,
'skip' => $from ,
'fields'=>array('projects' => TRUE)
));
}
}
当我尝试运行以下行时:
$projects_list = Mango::factory('project')->data_list($from, $this->list_items_per_page)->as_array();
我收到如下错误消息:
MongoCursorException [ 10105 ]: bad skip value in query
MODPATH\mongo\classes\mango\iterator.php [ 108 ]
103 /**
104 * Iterator: rewind
105 */
106 public function rewind()
107 {
108 $this->_cursor->rewind();
109 }
110
111 /**
112 * Iterator: valid
113 */
此错误的原因是什么?如何解决此问题?
答案 0 :(得分:0)
当您将'skip'值传递给小于0的查询时会出现此错误。我建议将您传入的值打印为'skip'到'factory'函数进行确认。
不知道您的数据或调用该特定行的位置,我无法准确说明为什么传入负数,但这是错误的原因。