1

Following code gives me some trouble:

  /**
   *
   * finds all distinct values of HybridTypes for the Page Collection
   */
  def findDistinctTypeValues(): List[String] = {
    //cast all instances from Any to String
    val coll = dao.collection.distinct("hybridType") map (_.asInstanceOf[String])
    coll.toList
  }

The mongo console tells me that the corresponding query lasts about 4 seconds. The field is an indexed string.

Is there anything im doing particularly wrong?

Update: This is the output of the runcommand:

db.runCommand({distinct: 'pages',key:'hybridType'})
     "stats" : {
             "n" : 2492192,
             "nscanned" : 2492192,
             "nscannedObjects" : 0,
             "timems" : 4247,
             "cursor" : "BtreeCursor hybridType_1"
     },
     "ok" : 1

Looks like its performing a full table scan? :/

Stefan Kunze
  • 741
  • 6
  • 15
  • 1
    What are the indexes for the collection? How many documents in the collection. If the field is indexed then it should just be able to use the index for the distinct. – Ross Oct 23 '13 at 09:27
  • there are 2,5 million documents in the collection and it has 4 indexes on it. It takes 4 seconds just to perform the query. Which is not acceptable for me. – Stefan Kunze Oct 23 '13 at 09:42
  • Can you run the distinct query in the shell and output the full response (eg the stats) – Ross Oct 23 '13 at 13:27
  • running "db.pages.distinct('hybridType').explain()" gives me a missing method error. What would you recommend to use? explain or anything else? – Stefan Kunze Oct 23 '13 at 16:11
  • 1
    You need to use runCommand - see: http://stackoverflow.com/questions/8429936/how-do-you-explain-a-distinct-query-in-mongodb – Ross Oct 25 '13 at 09:10
  • Hey, Ross do you have any idea on how to improve that? :) – Stefan Kunze Oct 28 '13 at 13:30

0 Answers0