【问题标题】:Maintain unique value in mongoose js not working在 mongoose js 中保持唯一值不起作用
【发布时间】:2017-01-19 19:37:01
【问题描述】:

我已经尝试过寻找答案,这是我目前尝试过的选项

email: {type: mongoose.SchemaTypes.Email, required: true, index : {unique: true}}
email: {type: mongoose.SchemaTypes.Email, required: true, unique: true},

我仍然使用数据库中使用的相同电子邮件插入。我哪里错了。

【问题讨论】:

    标签: node.js mongodb mongoose mongoose-schema


    【解决方案1】:

    这里是对我有用的代码

    email    : {type: mongoose.SchemaTypes.Email, required: true,index: {unique: true, dropDups: true}},
    

    另外请记住,您需要重新启动 mongodb 服务器。

    【讨论】:

      猜你喜欢
      • 2016-09-11
      • 2022-01-24
      • 2020-04-13
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      相关资源
      最近更新 更多