4

我有这个课程:

/**
 * @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;
}

我想在产品文档上应用多个复合索引。我想添加到数据库的索引如下:

{ "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 }

我的索引注释是否正确?似乎第一个索引必须是正确的,但我认为第二个和第三个索引不正确!

4

1 回答 1

2

我认为 ODM 尚无法应用索引。您可能需要在 mongo.exe 命令行中通过如下命令应用索引:

use yourDbName
db.ensureIndexes()
于 2013-08-24T08:19:09.490 回答