From 25c305db67e47e6560ad2adf252b9713d89a3344 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 13 Sep 2018 09:18:29 -0400 Subject: [PATCH] docs(model): add blog post link and example to syncIndexes() docs --- lib/model.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/model.js b/lib/model.js index 49eef8eadb8..aca9f9faf13 100644 --- a/lib/model.js +++ b/lib/model.js @@ -1027,6 +1027,17 @@ Model.init = function init(callback) { * 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. + * + * See the [introductory blog post](http://thecodebarbarian.com/whats-new-in-mongoose-5-2-syncindexes) + * for more information. + * + * ####Example: + * + * const schema = new Schema({ name: { type: String, unique: true } }); + * const Customer = mongoose.model('Customer', schema); + * await Customer.createIndex({ age: 1 }); // Index is not in schema + * // Will drop the 'age' index and create an index on `name` + * await Customer.syncIndexes(); * * @param {Object} [options] options to pass to `ensureIndexes()` * @param {Function} [callback] optional callback