如何为嵌套的Mongoose文档设置select = false?

时间:2015-08-14 16:19:43

标签: javascript mongoose

这是我的用户架构:

var userSchema = mongoose.Schema({
  profile: {
    username: { type: String, required: true, unique: true },
    role: String
  },
  auth: {
    hashedPassword: { type: String, required: true },
    facebookToken: String,
    twitterToken: String,
    googleToken: String
  },
});

我想为整个select = false对象设置auth。我该怎么做?

1 个答案:

答案 0 :(得分:4)

只需这样添加:

var userSchema = mongoose.Schema({
  profile: {
    username: { type: String, required: true, unique: true },
    role: String
  },
  auth: {
    type : {
      hashedPassword: { type: String, required: true },
      facebookToken: String,
      twitterToken: String,
      googleToken: String
    },
    select: false //<---- added here
  }
});