需要Mongoose.js上的几列之一

在Mongoose.js中,是否有任何方法只需要一个(或多个,但不是全部)多个列? 就我而言,我正在使用Passport,并希望我的用户通过我提供的提供商之一进行注册,或者自行创build。 不过,我不想要求用户通过任何一个提供商注册,而是要求他/她希望的任何一个。

下面是一个示例架构,来自Passport上的scotch.io教程 ( 注意 :这是一个例子,我不打算在我的应用中使用它,但可能使用类似的东西):

 // app/models/user.js // load the things we need var mongoose = require('mongoose'); var bcrypt = require('bcrypt-nodejs'); // define the schema for our user model var userSchema = mongoose.Schema({ local : { email : String, password : String, }, facebook : { id : String, token : String, email : String, name : String }, twitter : { id : String, token : String, displayName : String, username : String }, google : { id : String, token : String, email : String, name : String } }); // methods ====================== // generating a hash userSchema.methods.generateHash = function(password) { return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); }; // checking if password is valid userSchema.methods.validPassword = function(password) { return bcrypt.compareSync(password, this.local.password); }; // create the model for users and expose it to our app module.exports = mongoose.model('User', userSchema); 

我如何要求在保存文档之前至less指定了一个对象localfacebooktwitter或者google (不为null ,没有undefined等),而没有使用任何一个对象(而其他的不需要需要)或使所有这些都是必需的? 就应用而言,这将使用户被要求首次通过用户名和密码进行注册; Twitter或Facebook OAuth帐户或Google+ OpenID帐户。 然而,用户不会被绑定到任何一个提供商,所以他/她不需要通过用户名和密码进行注册,但是如果不是他/她,他/她也不必通过社交networking账户注册事情。