v5.11.0
Added
- Connection hooks to
Iridium.Core
in the form of onConnecting and onConnected. - Added a link to the new documentation to the README file.
Description
Connection hooks allow you to implement custom logic controlling the way in which Iridium's Core both creates its database connection, as well as being notified once the connection has been established. This comes in very handy for implementing automatic index generation for your models.
Here's an example of how one would go about automatically setting up your indexes for a model when the database connection is established. It is important to be aware that, unless your indexes are set to { background: true }
, this operation will block the completion of the Iridium.Core.connect method - and generating indexes on a large database can take some time...
class MyCore extends Iridium.Core {
MyModel = new Iridium.Model<MyModelDocument, MyModelInstance>(this, MyModelInstance);
protected onConnected() {
return this.MyModel.ensureIndexes();
}
}