我有这样的类:
/**
* @ODMDocument
* @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 {
/**
* @ODMDate
*/
protected $regDate;
/**
* @ODMDate
*/
protected $expire;
/**
* @ODMEmbedOne(targetDocument="Price")
*/
protected $price;
/**
* @ODMBoolean
*/
protected $isFeatured;
/**
* @ODMEmbedMany(targetDocument="Visit")
*/
protected $visits;
}
/**
* @ODMEmbeddedDocument
*/
class Price {
/**
* @ODMInt
*/
protected $value;
/**
* @ODMString
*/
protected $currency;
}
/**
* @ODMEmbeddedDocument
*/
class Visit {
/**
* @ODMInt
*/
protected $total;
/**
* @ODMInt
*/
protected $today;
/**
* @ODMEmbedMany(targetDocument="VisitPerDate")
*/
protected $perDate = array();
}
/**
* @ODM|EmbeddedDocument
*/
class VisitPerDate {
/**
* @ODMDate
*/
protected $date;
/**
* @ODMInt
*/
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 }
我的索引注释正确吗?似乎第一个索引必须是正确的,但我认为第二个和第三个索引是不正确的!
我认为ODM还不可能应用索引。您可能需要通过mongo.exe命令行中的以下命令应用索引:
use yourDbName
db.ensureIndexes()