我在互联网上搜索了两天,没有找到任何答案,
const mongoose = require('mongoose');
const channelsSchema = new mongoose.Schema(
{
stateName: {
type: String,
required: [true, 'A state must have a name'],
unique: true,
index:true
},
id: {
type:String
},
Name: {
type:String
},
**anyThing: [Object]
},
{ strict: false }
);
const Channels = mongoose.model('Channels', channelsSchema);
module.exports = Channels;
有什么办法可以接受任何东西吗?
注意:这不是一个大项目,我不担心安全问题。它只在本地运行
您可以将{strict: false}
作为第二个参数传递给Schema来实现这一点。
const mongoose = require('mongoose');
const channelsSchema = new mongoose.Schema({}, {strict: false})
const Channels = mongoose.model('Channels', channelsSchema);
module.exports = Channels;