Mongoose Changing Schema Format

There's nothing built into Mongoose regarding migrating existing documents to comply with a schema change. You need to do that in your own code, as needed. In a case like the new enabled field, it's probably cleanest to write your code so that it treats a missing enabled field as if it was set to false so you don't have to touch the existing docs.

As far as the schema change itself, you just update your Schema definition as you've shown, but changes like new fields with default values will only affect new documents going forward.


Considering your Mongoose model name as sweepstakesModel, this code would add enabled field with boolean value false to all the pre-existing documents in your collection:

db.sweepstakesModel.find( { enabled : { $exists : false } } ).forEach(
    function (doc) {
        doc.enabled = false;
        db.sweepstakesModel.save(doc);
    }
)