2

I need to select distinct values from a mongoDB collection. As is described in docs here for this can be used "distinct". But it returns only the fields that was used in distinct condition (ArrayIterator object), not as loggable cursor object:

    object(Doctrine\MongoDB\ArrayIterator)[1072]
  private 'elements' => 
    array (size=2)
      0 => int 39
      1 => int 47
  private 'commandResult' => 
    array (size=3)
      'values' => 
        array (size=2)
          0 => int 39
          1 => int 47
      'stats' => 
        array (size=5)
          'n' => int 60
          'nscanned' => int 71
          'nscannedObjects' => int 71
          'timems' => int 0
          'cursor' => string 'BasicCursor' (length=11)
      'ok' => float 1
user2623505
  • 309
  • 5
  • 14
  • What else did you hope it would return? This is just what distinct does in MongoDB: give you an array of distinct values. – dylan oliver Dec 17 '13 at 00:19
  • I expect that distinct in Mongo work as distinct in Doctrine 2 ORM (MySQL DISTINCT with multiple columns - it return an array of values and can also be selected multiple fields from the table). In Mongo ODM module, I got only the field that i choosed to be as distinct (only one field is selected). – user2623505 Dec 18 '13 at 08:08
  • To be more clear I expect a result as it is described here (for Mysql) - http://www.w3resource.com/sql/select-statement/queries-with-distinct-multiple-columns.php – user2623505 Dec 18 '13 at 08:43
  • Just slap an additional ->count() on the execute() and you are all set! – Marin Purgar May 21 '14 at 14:36

0 Answers0