有没有办法用猫鼬模式自动填充mongodb?

时间:2018-12-12 07:19:58

标签: mongoose

好吧,我的问题是这样的:如果我添加到架构中,如果该字段不存在,是否可以自动填充用户?

const mongoose = require('mongoose');

// User Schema
const UserSchema = mongoose.Schema({
  email:{
    type: String,
    required: true
  },
  username:{
    type: String,
    required: true
  },
  password:{
    type: String,
    required: true
  },
  registered: {
    type: Date,
    default: Date.now()
  },
  currency:{
    type: Object,
    default: {
      cs: 100,
      os: 100
    }
  },
});

const User = module.exports = mongoose.model('User', UserSchema);

好的,所以当您注册时可以,但是说我要在注册后添加一个新类型,例如:

  test: {
    type: String,
    default: 'This is a test'
  }

因此,使用的数据库中没有此功能。如果他们不存在该字段,是否有办法自动填充?

0 个答案:

没有答案
相关问题