相关疑难解决方法(0)

如何防止 Moongoose 中的字段更新

我有一个看起来像这样的架构:

"use strict"

const mongoose = require('mongoose');
const timestamp  = require('mongoose-timestamp');

const CustomerSchema = new mongoose.Schema({
    name : {
        type : String,
        required : true,
        trim : true
    },
    email : {
        type : String,
        required : true,
        trim : true
    },
    balance : {
        type : Number ,
        default : 0
    }
})

//use timestamps to add created at and updated at
CustomerSchema.plugin(timestamp);

const Customer = mongoose.model('Customer',CustomerSchema);

module.exports = Customer;
Run Code Online (Sandbox Code Playgroud)

当我想运行更新时,我运行此代码

const Customer = require('../models/Customer');
const customer =  await …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js

4
推荐指数
2
解决办法
1712
查看次数

标签 统计

mongodb ×1

mongoose ×1

node.js ×1