Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tarquas/mongoose-hook-ensure-indexes
A mongoose plugin, improving 'Model.ensureIndexes' method, allowing also deletion of unused indexes and reindexing with changed options.
https://github.com/tarquas/mongoose-hook-ensure-indexes
Last synced: about 2 months ago
JSON representation
A mongoose plugin, improving 'Model.ensureIndexes' method, allowing also deletion of unused indexes and reindexing with changed options.
- Host: GitHub
- URL: https://github.com/tarquas/mongoose-hook-ensure-indexes
- Owner: tarquas
- License: mit
- Created: 2015-03-18T18:27:51.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-23T15:49:32.000Z (almost 8 years ago)
- Last Synced: 2024-11-15T00:39:28.553Z (2 months ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongoose-hook-ensure-indexes
A mongoose plugin, improving 'Model.ensureIndexes' method, allowing also deletion of unused indexes and reindexing with changed options.# Installation
```shell
git clone [email protected]:tarquas/mongoose-hook-ensure-indexes.git mongoose-hook-ensure-indexes
```# Package
```js
{
"mongoose-hook-ensure-indexes": "0.1.4"
}
```# Usage
Example:
```js
var
mongoose = require('mongoose'),
ensureIndexes = require('mongoose-hook-ensure-indexes'),
PersonSchema;PersonSchema = {
name: String,
email: String
};PersonSchema.index({name: 1});
PersonSchema.index({email: 1}, {unique: true});PersonSchema.plugin(ensureIndexes, {mongoose: mongoose});
mongoose.model('Person', PersonSchema);
```# Notes
* This plugin must be provided with an exact instance of `mongoose`, where the processing models expected to be processed, in `opts` parameter.
* This plugin makes sure that no other indexes persist on MongoDB collection than those, which specified in Schema. New indexes get created. Obsolete indexes get dropped. Indexes with changed options get recreated and rebuilt.