2013-07-29 76 views
4

我有這個類:MongoDB ODM索引:如何在一個自己擁有EmbeddedDocument的文檔中索引多個複合索引?

/** 
* @ODM\Document 
* @Indexes({ 
* @Index(keys={"status"="asc", "regDate"="desc", "expDate"="asc", "isFeatured"="asc"}), 
* @Index(keys={"status"="asc", "visits.total"="asc", "visists.today"="asc"}), 
* @Index(keys={"status"="asc", "price.value"="asc", "regDate"="asc"}) 
* }) 
*/ 
class Product { 

    /** 
    * @ODM\Date 
    */ 
    protected $regDate; 

    /** 
    * @ODM\Date 
    */ 
    protected $expire; 

    /** 
    * @ODM\EmbedOne(targetDocument="Price") 
    */ 
    protected $price; 

    /** 
    * @ODM\Boolean 
    */ 
    protected $isFeatured; 

    /** 
    * @ODM\EmbedMany(targetDocument="Visit") 
    */ 
    protected $visits; 
} 

/** 
* @ODM\EmbeddedDocument 
*/ 
class Price { 
    /** 
    * @ODM\Int 
    */ 
    protected $value; 

    /** 
    * @ODM\String 
    */ 
    protected $currency; 
} 

/** 
* @ODM\EmbeddedDocument 
*/ 
class Visit { 
    /** 
    * @ODM\Int 
    */ 
    protected $total; 

    /** 
    * @ODM\Int 
    */ 
    protected $today; 

    /** 
    * @ODM\EmbedMany(targetDocument="VisitPerDate") 
    */ 
    protected $perDate = array(); 
} 

/** 
* @ODM|EmbeddedDocument 
*/ 
class VisitPerDate { 
    /** 
    * @ODM\Date 
    */ 
    protected $date; 

    /** 
    * @ODM\Int 
    */ 
    protected $visit; 
} 

我想在產品上應用Document.The指標我想添加到數據庫中的多個複合索引有以下幾種:

{ "status"=1, "regDate"=-1, "expDate"=1, "isFeatured"=1 } 
{ "status"=1, "visits.total"=1, "visits.today"=1, "regDate"=1 } 
{ "status"=1, "price.value"=1, "regDate"=1 } 

是我的索引標註是否正確? 看來,第一個索引必須是正確的,但我認爲第二個和第三個索引是不正確的!

回答

2

我認爲應用索引是不可能通過ODM。您可能需要按照mongo.exe命令行中的命令應用索引:

use yourDbName 
db.ensureIndexes()