jbl*_*lew 1 unique mongoose mongodb node.js express
我的节点应用程序中有一个user.js模型,我希望用户名和其他一些字段唯一。在我的模型文件中,我正确声明了unique如下所示的类型:
// User Schema
const UserSchema = new Schema({
// PERSONAL USER INFO
username: {
type: String,
required: true,
index: true,
unique: true,
},
email: {
type: String,
required: true,
index: true,
unique: true
},
password: {
type: String,
required: true,
},
....
});
Run Code Online (Sandbox Code Playgroud)
但是,在重新启动服务器和mongo会话之后,我仍然可以使用相同的用户名和相同的电子邮件创建用户。我可以从mongo shell和前端用户注册页面上执行此操作。
我还缺少第二部分吗?我现在不确定如何正确执行该unique类型。谢谢!
| 归档时间: |
|
| 查看次数: |
2052 次 |
| 最近记录: |