小编Ped*_*que的帖子

如何使用对象数组创建猫鼬模式

我有这个json:

{
    "data": [
        "id": "1",
        "name": "Sample test",
        "description": "this is a sample test",
        "category": "tests",
        "points": 100,
        "startDate"?:?"2018-02-15 00:00:00"?,
        "endDate"?:?"2018-02-22 00:00:00"?,
        "isActive"?:?true?,
        "alreadyAnswered"?:?false?,
        "questions"?:[
            {
                "id": 1,
                "text": "What is your name",
                "type": "text",
            },
            {
                "id": 2,
                "text": "What is your favorite color",
                "type": "select",
                "options": [
                    {
                        "id": 1,
                        "text": "Red",
                        "value": "red"
                    },
                    {
                        "id": 2,
                        "text": "Blue",
                        "value": "blue"
                    }
                ]
            }
        ]
    ]
}
Run Code Online (Sandbox Code Playgroud)

我需要将此json创建到mongo数据库中,以便可以通过节点应用程序获取它。

这是我当前的模式:

let TestSchema = new Schema({
    id: Number, …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js mongoose-schema

4
推荐指数
1
解决办法
5767
查看次数

标签 统计

mongodb ×1

mongoose-schema ×1

node.js ×1