From f98e65c174f062c4a9641538707778596c4e18b4 Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Thu, 17 Jan 2019 22:27:26 +0100 Subject: [PATCH] mongoose: add syncIndexes and listIndexes missingModel methods --- types/mongoose/v4/index.d.ts | 30 +++++++++++++++++++++++++++-- types/mongoose/v4/mongoose-tests.ts | 4 ++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/types/mongoose/v4/index.d.ts b/types/mongoose/v4/index.d.ts index e38317ae5d..8f8029a2e1 100644 --- a/types/mongoose/v4/index.d.ts +++ b/types/mongoose/v4/index.d.ts @@ -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 , horiuchi , lukasz-zak +// Definitions by: simonxca +// horiuchi +// lukasz-zak +// Emmanuel Gautier // 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; + /** + * 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; + + /** + * 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; + /** * Sends ensureIndex commands to mongo for each index declared in the schema. * @param options internal options diff --git a/types/mongoose/v4/mongoose-tests.ts b/types/mongoose/v4/mongoose-tests.ts index 633d3438a8..95770c0305 100644 --- a/types/mongoose/v4/mongoose-tests.ts +++ b/types/mongoose/v4/mongoose-tests.ts @@ -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) {