Chris T Chris T - 6 months ago 72
Node.js Question

How do you use Mongoose without defining a schema?

In previous versions of Mongoose (for node.js) there was an option to use it without defining a schema

var collection = mongoose.noSchema(db, "User");

But in the current version the "noSchema" function has been removed. My schemas are likely to change often and really don't fit in with a defined schema so is there a new way to use schema-less models in mongoose?


I think this is what are you looking for Mongoose Strict

option: strict

The strict option, (enabled by default), ensures that values added to our model instance that were not specified in our schema do not get saved to the db.

Note: Do not set to false unless you have good reason.

    var thingSchema = new Schema({..}, { strict: false });
    var thing = new Thing({ iAmNotInTheSchema: true }); // iAmNotInTheSchema is now saved to the db!!