gpt4 book ai didi

MongoDB ODM 索引 : How to Index multiple Compound index on a documnt that have EmbeddedDocument in itself?

转载 作者:可可西里 更新时间:2023-11-01 09:14:26 24 4
gpt4 key购买 nike

我有这个类(class):

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

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

最佳答案

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

use yourDbName
db.ensureIndexes()

关于MongoDB ODM 索引 : How to Index multiple Compound index on a documnt that have EmbeddedDocument in itself?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17915543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com