Mongoose model init (#25530)

* Adding init method declaration on Model interface

* Test init method on Model
This commit is contained in:
Philip Andersson
2018-05-04 22:49:48 +02:00
committed by Andy
parent 15df8a32af
commit ebf9f31259
2 changed files with 11 additions and 0 deletions

View File

@@ -2714,6 +2714,16 @@ declare module "mongoose" {
insertMany(doc: any, callback?: (error: any, doc: T) => void): Promise<T>;
insertMany(doc: any, options?: { ordered?: boolean, rawResult?: boolean }, callback?: (error: any, doc: T) => void): Promise<T>;
/**
* Performs any async initialization of this model against MongoDB.
* This function is called automatically, so you don't need to call it.
* This function is also idempotent, so you may call it to get back a promise
* that will resolve when your indexes are finished building as an alternative
* to `MyModel.on('index')`
* @param callback optional
*/
init(callback?: (err: any) => void): Promise<T>;
/**
* Executes a mapReduce command.
* @param o an object specifying map-reduce options

View File

@@ -1420,6 +1420,7 @@ var MongoModel = mongoose.model('MongoModel', new mongoose.Schema({
required: true
}
}), 'myCollection', true);
MongoModel.init().then(cb);
MongoModel.find({}).$where('indexOf("val") !== -1').exec(function (err, docs) {
docs[0].save();
docs[0].__v;