无法从MongoDb检索数据

时间:2014-04-27 15:25:37

标签: php mongodb yii

检索逻辑就像这样...... 有一个集合USERS,,每个用户都关联一个数组 [],其中包含文件ID。

我有另一个集合TraceInfo, ,其中包含具有各自ID的实际文件。 我正在使用这个逻辑检索有关文件的信息..这非常正常。

$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
    )));

只更改我所做的是,现在我想存储相同的文件ID []也是Customer Collection,n检索属于同一客户的文件。

为此,这是我已更改的代码部分,但它似乎没有,工作...我猜错误可能在查询中,我检查了UMONGO,客户的关联数组,其中包含文件ID得到了更新。

这是代码。 任何人都可以告诉我们查询有什么问题,或者我需要做什么改变才能做到,我想要什么。 (检索属于特定客户的文件)

$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
    )));

1 个答案:

答案 0 :(得分:1)

$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错误,是通过cust_id搜索col_trace_info,而需要通过_Id搜索它,这是收集跟踪的主键。

相关问题