Mongoose strict option
JS
S
JavaScriptUse the strict options object to bypass schema definitions and insert more fields which are not on Schema
1// lib/models/item.model.ts
2import * as mongoose from 'mongoose'
3
4const options = {
5 strict: false
6};
7
8const itemSchema = new mongoose.Schema({
9 name: String,
10 description: String,
11 category: String,
12},options)
13
14const Item = mongoose.model('Item', itemSchema)
15
16export { Item };
17
18// router/api/index.ts
19import { Item } from '../models/item.model';
20const doc = new Item({name: 'test', description: 'test desc', category: 'samples', code: 1222 });
21doc.save();Created on 1/7/2018