We use MongoDB to collect logs on pageviews.
$collection_name = "logs.".date('Y').".".date('m').".".date('d');
$collection = $this->Mongo->$collection_name;
$collection->insert($pageview);
The code above creates a new collection for every day.
I would like to be able to create an index on the above collection when it is created. Is there anyway to do this?
- In a traditional RDBMS, this is accomplished through the schema. Is there anything similar in MongoDB? Is it possible to configure the database to create indexes on new collections?
- If not, what is the best way to accomplish this in PHP? I don't want to call ensureIndex everytime I call insert