【问题标题】:MongoDB doesn't contain field, but when request is sent this field is shownMongoDB 不包含字段,但发送请求时会显示此字段
【发布时间】:2021-10-19 18:54:33
【问题描述】:

我有这样的架构

{
        "quantity": 0,
        "_id": "6156ec720c5074fbd3739074",
        "title": "Adidas nite jogger",
        "description": "description adidas.Lorem ipsum dolor, sit amet consectetur adipisicing elit. Molestias facere deserunt, quaerat distinctio officiis eligendi culpa sequi molestiae voluptatem velit, ab facilis quae sint vel obcaecati, incidunt ducimus odio",
        "price": 75,
        "__v": 0
}

在邮递员中发送请求时会显示数量字段,但是当我查看我的数据库时,我看到的是这样的MongoDB table

所以没有这样的字段,所以我也想在 Postman 中删除它。

我尝试使用$unset,但它不起作用/ 对不起我的英语:)

【问题讨论】:

    标签: javascript mongodb express mongoose mongoose-schema


    【解决方案1】:

    此属性由 mongoose 添加,而不是由 mongodb 服务器添加,要删除它,您只需修改您的架构声明:

    const yourSchema = new Schema({...}, { versionKey: false });
    

    【讨论】:

    • 对不起,我完成后数量没有被删除。我想在 Postman 上发送请求时删除“数量”字段,而不是“__v”字段。实际上我在数据库中没有“数量”字段,但在发送请求时有它。
    猜你喜欢
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多