【问题标题】:MongoDB ODM Indexing : How to Index multiple Compound index on a documnt that have EmbeddedDocument in itself?MongoDB ODM 索引:如何在本身具有 EmbeddedDocument 的文档上索引多个复合索引?
【发布时间】:2013-07-28 17:47:57
【问题描述】:

我有这些课程:

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

我的索引注释是否正确? 看来第一个索引一定是正确的,但我认为第二个和第三个索引不正确!

【问题讨论】:

    标签: mongodb doctrine-orm doctrine-odm odm


    【解决方案1】:

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

    use yourDbName
    db.ensureIndexes()
    

    【讨论】:

      猜你喜欢
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 2016-10-19
      • 2012-11-16
      • 1970-01-01
      • 2012-03-24
      相关资源
      最近更新 更多