From 8d45b2e1be22cba3e4a0d223328d6cad4fc016d1 Mon Sep 17 00:00:00 2001 From: ulrichb Date: Mon, 25 Mar 2019 21:44:15 +0100 Subject: [PATCH] Add `Model.createCollection()` (#34193) --- types/mongoose/index.d.ts | 6 ++++++ types/mongoose/mongoose-tests.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index ac01ba61bf..a56e14a086 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -2989,6 +2989,12 @@ declare module "mongoose" { create(...docs: any[]): Promise; create(...docsWithCallback: any[]): Promise; + /** + * Create the collection for this model. By default, if no indexes are specified, mongoose will not create the + * collection for the model until any documents are created. Use this method to create the collection explicitly. + */ + createCollection(options?: mongodb.CollectionCreateOptions, cb?: (err: any) => void): Promise; + /** * Adds a discriminator type. * @param name discriminator model name diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index 6eda6d5eb0..5f2dd1bbc6 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -1648,6 +1648,9 @@ MongoModel.create([{ type: 'jelly bean' }, { arg[0].save(); arg[1].save(); }); +MongoModel.createCollection().then(() => {}); +MongoModel.createCollection({ capped: true, max: 42 }).then(() => {}); +MongoModel.createCollection({ capped: true, max: 42 }, err => {}); MongoModel.distinct('url', { clicks: {$gt: 100}}, function (err, result) { }); MongoModel.distinct('url').exec(cb);