mongoose-any-index
Mongoose plugin that adds some additional functionality to mongoose indexes:
-
Lets you add arbitrary indexes to any path, regardless of whether it's specified in your schema. The typical case is when you want sparse indexes within a Mixed type:
any_index = require 'mongoose-any-index'Awesome =email: type: Stringindex: trueunique: truerequired: truetags: type: Stringdata: type: SchemaTypesMixedAwesomeplugin any_indexkeys: 'data.nested_field': 1 options: unique: truesparse: true -
Adds a
Model.fullEnsureIndexes(cb)
static method that drops indexes not specified in your schema. This lets you avoid "index bloat", since mongoose'sModel.ensuresIndexes(cb)
by default does not calldropIndex
on pre-existing indexes.
Installation
npm install mongoose-any-index