我有一个名为“公司”的 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库。
我想编写一个函数来检索所有项目并为用户列出它们(检索字段子集)。
这是我的公司模型:
<?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 */
这个错误的原因是什么,我该如何解决这个问题?