mongoose: add syncIndexes and listIndexes missingModel methods

This commit is contained in:
Emmanuel Gautier
2019-01-17 22:41:21 +01:00
parent bf908def12
commit f98e65c174
2 changed files with 32 additions and 2 deletions
+28 -2
View File
@@ -1,6 +1,9 @@
// Type definitions for Mongoose 4.7.1
// Type definitions for Mongoose 4.7.2
// Project: http://mongoosejs.com/
// Definitions by: simonxca <https://github.com/simonxca>, horiuchi <https://github.com/horiuchi>, lukasz-zak <https://github.com/lukasz-zak>
// Definitions by: simonxca <https://github.com/simonxca>
// horiuchi <https://github.com/horiuchi>
// lukasz-zak <https://github.com/lukasz-zak>
// Emmanuel Gautier <https://github.com/emmanuelgautier>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -2499,6 +2502,29 @@ declare module "mongoose" {
distinct(field: string, conditions: any,
callback?: (err: any, res: any[]) => void): Query<any[]>;
/**
* Makes the indexes in MongoDB match the indexes defined in this model's
* schema. This function will drop any indexes that are not defined in
* the model's schema except the `_id` index, and build any indexes that
* are in your schema but not in MongoDB.
* @param options options to pass to `ensureIndexes()`
* @param callback optional callback
* @return Returns `undefined` if callback is specified, returns a promise if no callback.
*/
syncIndexes(options: object, callback?: (err: any) => void): void;
syncIndexes(options: object): Promise<void>;
/**
* Lists the indexes currently defined in MongoDB. This may or may not be
* the same as the indexes defined in your schema depending on whether you
* use the [`autoIndex` option](/docs/guide.html#autoIndex) and if you
* build indexes manually.
* @param cb optional callback
* @return Returns `undefined` if callback is specified, returns a promise if no callback.
*/
listIndexes(callback: (err: any) => void): void;
listIndexes(): Promise<void>;
/**
* Sends ensureIndex commands to mongo for each index declared in the schema.
* @param options internal options
+4
View File
@@ -1361,6 +1361,10 @@ MongoModel.create([{ type: 'jelly bean' }, {
MongoModel.distinct('url', { clicks: {$gt: 100}}, function (err, result) {
});
MongoModel.distinct('url').exec(cb);
MongoModel.syncIndexes({});
MongoModel.syncIndexes({}, cb);
MongoModel.listIndexes();
MongoModel.listIndexes(cb);
MongoModel.ensureIndexes({}, cb);
MongoModel.find({ name: 'john', age: { $gte: 18 }});
MongoModel.find({ name: 'john', age: { $gte: 18 }}, function (err, docs) {