Reputation: 541
retrieval logic is like this... there is a collection USERS, with each user i associate an array [] which contains, ID of files.
I have another collection TraceInfo, which contains actual Files with their Respective IDs. and i was retrieving info about files using this logic.. which works absolutely fine.
$doc = $this->col_users->findOne(array('_id'=>$this->options['user_id']), array($array_name=>True));
$doc[$array_name] = (isset($doc[$array_name])) ? $doc[$array_name] : array();
$cursor = $this->col_trace_info ->find(array('_id'=>array('$in'=>$doc[$array_name])),
array('name'=>True, 'size'=>True, 'notes'=>True, 'shared_flag'=>True, 'is_radius'=>True))
->sort(array('_id'=>-1));
$file_list = array();
if($cursor->count() > 0)
foreach ($cursor as $doc) {
if ($iteration_method == 'get_file_object') {
if ($shared_in) $doc['shared_in'] = True;
else $doc['shared_in'] = False;
$file_list[] = $doc;
}
else if ($iteration_method == 'is_valid_file_object') {
$file_list[] = $doc['_id'];
}
}
return array_values(array_filter(array_map(
array($this, $iteration_method),
$file_list
)));
Only change that i made is, now i want to store same file ID [] is Customer Collection as well, n retrieve files belonging to same customer.
for which, this is the section of code i have changed, but it seem to not, work... i guess mistake might be in query, i checked in UMONGO, customer's associative array which contains file ID got updated.
Here is the Code for that. Can anybody tell be what is wrong with query, or what changes do i need to make in order do, what i desire. (retrieve files which belong to particular customer)
$doc = $this->col_customers->findOne(array('cust_id'=>$this->options['cust_id']), array($array_name=>True));
$doc[$array_name] = (isset($doc[$array_name])) ? $doc[$array_name] : array();
$cursor = $this->col_trace_info ->find(array('cust_id'=>array('$in'=>$doc[$array_name])),
array('name'=>True, 'size'=>True, 'notes'=>True, 'shared_flag'=>True, 'is_radius'=>True))
->sort(array('cust_id'=>-1));
$file_list = array();
if($cursor->count() > 0)
foreach ($cursor as $doc) {
if ($iteration_method == 'get_file_object') {
$file_list[] = $doc;
}
else if ($iteration_method == 'is_valid_file_object') {
$file_list[] = $doc['cust_id'];
}
}
return array_values(array_filter(array_map(
array($this, $iteration_method),
$file_list
)));
Upvotes: 1
Views: 118
Reputation: 541
$cursor = $this->col_trace_info ->find(array('_id'=>array('$in'=>$doc[$array_name])),
array('name'=>True, 'size'=>True, 'notes'=>True, 'shared_flag'=>True, 'is_radius'=>True))
->sort(array('_id'=>-1));
sillly mistake, was searching the col_trace_info by cust_id, whereas needed to search it by _Id, this is primary key for collection of traces.
Upvotes: 1