2013-12-17 40 views
0

我有一個數組,它是Mongodb的一個過濾器。 但它不起作用,我不明白爲什麼。MongoDB過濾

Array 
(
[deleted] => Array 
    (
     [$ne] => 1 
    ) 

    [public] => 1 
    [_id] => Array 
     (
      [$nin] => Array 
       (
        [0] => MongoId Object 
         (
          [$id] => 525becec38aa9e28201f1d68 
         ) 
        [1] => MongoId Object 
         (
          [$id] => 525becb438aa9e963a1f1d55 
         ) 
        [2] => MongoId Object 
         (
          [$id] => 525bec7438aa9e8d3a1f1d56 
         ) 
        [3] => MongoId Object 
         (
          [$id] => 525bec1438aa9e6c6d1f1d69 
         ) 
        [4] => MongoId Object 
         (
          [$id] => 525bebcf38aa9e8c3a1f1d57 
         ) 
        [5] => MongoId Object 
         (
          [$id] => 525beb3038aa9e8d3a1f1d55 
         ) 
       ) 
     ) 
) 

我需要找到標識符不在列表中的所有對象。

+0

這是什麼編程語言?我認爲這可能是PHP,但我不確定。請添加適當的標籤。 – Philipp

+0

我不明白你想要做什麼。請更具體一些,並告訴我們你已經嘗試過了。 MongoDB查詢必須完成什麼? – Thibault

+0

我試圖讓所有的對象不包含在列表中,數組中的列表$ nin if(!empty($ profile ['answers']))$ filter ['_ id'] ['$ nin '] [] = $ profile ['回答'];; if(!empty($ profile ['wrongAnswered']))$ filter ['__in''] ['$ nin'] = $ profile ['wrongAnswered']; ($ filter) - > limit(1) - > sort(array('gallery.0'=> -1)); – user3111364

回答

0

您的查詢應該是這樣的:

$filter = array(
    '_id' => array(
     '$nin' => array(
       new MongoId('525becec38aa9e28201f1d68'), 
       //etc... 
     ) 
    ), 
    'deleted' => array(
      '$ne' => 1 
    ) 

); 

$result = $this->mongo->questions->find($filter)->sort(//however you're sorting); 

不知道爲什麼你結果限制爲1號文件,除非那是你真正想要的。