ODM Indexing MongoDB: How to index a multiple federated index on a documnt that has an EmbeddedDocument on its own?

I have the following classes:

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

I want to apply some composite indexes in a product document. The indexes I want to add to the database are as follows:

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

Was the correct annotation for indexing? It seems that the first index should be correct, but I believe that the second and third indexes are incorrect!

+4
source share
1 answer

I think that applying indexes is not yet possible with ODM. You may need to use indexes with a command like this on the mongo.exe command line:

 use yourDbName db.ensureIndexes() 
+2
source

Source: https://habr.com/ru/post/1493999/


All Articles