I have a mongo collection called "companies" which looks like this :
{
"_id" : ObjectId("..."),
"name" : "company_1",
"active" : false,
"projects" : [
{
"_id" : ObjectId("..."),
"name" : "Prj_1",
...
},
{
"_id" : ObjectId("..."),
"name" : "Prj_2" ,
...
}
],
"rating" : 0,
...
}
...
I am using Kohana 3.2 as my framework and MangoDb library.
I want ot write a function to retrieve all the projects and list them for the user (Retrieving a Subset of Fields).
This is my company model:
<?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 ));
}
}
This is the embedded project model:
<?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)
));
}
}
When I try to run the line below:
$projects_list = Mango::factory('project')->data_list($from, $this->list_items_per_page)->as_array();
I get an error message listed below:
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 */
What is the cause of this error and how can I solve this issue?