如何在没有数据建模的情况下对猫鼬数据进行CRUD

时间:2020-04-24 07:43:12

标签: node.js mongodb mongoose crud

我现在在互联网上搜索了2天,没有找到答案,

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;

有什么办法可以使任何东西接受任何东西吗?

注意:这不是一个大项目,我也不担心安全性。它只在本地运行

1 个答案:

答案 0 :(得分:0)

您可以将{strict: false}作为第二个参数传递给Schema来实现。

const mongoose = require('mongoose');

const channelsSchema = new mongoose.Schema({}, {strict: false})
const Channels = mongoose.model('Channels', channelsSchema);
module.exports = Channels;