【问题标题】:create mongoose schema for this object from mongodb从 mongodb 为这个对象创建 mongoose 模式
【发布时间】:2021-11-02 23:24:05
【问题描述】:

我想根据这个模型架构创建一个架构。

[
    {
        "_id": "617dda9ec688cc58f8db259e",
        "location": "The Hunt Club",
        "numbers": 12,
        "available": [true, false]
    }
]

到目前为止,我有以下代码,但似乎没有工作:

const locationSchema = new mongoose.Schema({
    location: {
        type: "string",
        required: true
    },
    numbers:{
        type: "number",
        required: true
    },
    available:{
        type:[Boolean],
        required: true
    },
    date:{
        type:Date,
        default:Date.now,
    }
})

const locations = mongoose.model('location', locationSchema);
module.exports = locations;

【问题讨论】:

    标签: node.js mongodb express mongoose


    【解决方案1】:

    在文档https://mongoosejs.com/docs/guide.html 为了定义元素的类型,类型将被解释。您可以使用本机类型 String 而不是 "string"Number

    numbers:{
        type: Number,
        required: true
    },
    

    【讨论】:

      猜你喜欢
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 2018-02-28
      • 2022-07-18
      • 2013-02-01
      • 2020-04-04
      • 2014-04-10
      相关资源
      最近更新 更多