如何使用猫鼬在mongodb中为对象数组创建模型

时间:2020-08-20 13:28:57

标签: mongodb

我正在为这样的对象数组创建模型,但是在我的mongodb中,它的存储方式是这样的

const sellSchema = new mongoose.Schema({
        items: [
            {
                type: String,
                detail: String,
                price: String,
                quantity: String
            }
        ]
    })

我这样在邮递员中张贴

[
    {
    "detail": "coffee",
    "price": "25",
    "quantity": "2"
},
{
    "detail": "sandwhich",
    "price": "30",
    "quantity": "1"
}
]

但是这样来

{
    "status": "success",
    "data": [
        {
            "items": [],
            "_id": "5f3e79464fd8372ba4c8ba9b",
            "__v": 0
        },
        {
            "items": [],
            "_id": "5f3e79464fd8372ba4c8ba9c",
            "__v": 0
        }
    ]
}

0 个答案:

没有答案