반응형

option: strict

strict 옵션을 이용하면 특정 스키마를 지정하지 않아도되는 모델을 만들 수 있다.

 

즉, 모델에 스키마 지정이 안되있으므로 {a: 1}도 들어갈 수 있고 {employeeNumber: "12345"}도 들어갈 수 있다.

 

하지만 특정한 목적이 있지 않고 일반적인 경우에는 strict: false를 사용하지 않고 스키마를 지정하는 것을 권장한다. 

 

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 = mongoose.model('Thing', thingSchema);
var thing = new Thing({ iAmNotInTheSchema: true });
thing.save() // iAmNotInTheSchema is now saved to the db!!

 

https://stackoverflow.com/questions/5370846/how-do-you-use-mongoose-without-defining-a-schema

 

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" fu...

stackoverflow.com

 

반응형