【问题标题】:How do i create composite unique key in mongoDB如何在 mongoDB 中创建复合唯一键
【发布时间】:2016-08-09 17:12:43
【问题描述】:

如何在 mongodb 的集合中的多个列上创建唯一键。就像我们使用这个添加唯一 unique_index(user, email, phonenumber);在sql中。

【问题讨论】:

    标签: node.js mongodb mongoose nosql


    【解决方案1】:

    试试这样的

    db.members.createIndex( { groupNumber: 1, lastname: 1, firstname: 1 },
    { unique: true } )
    

    查看此链接了解更多信息 mongodb create unique index

    【讨论】:

      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 2016-04-12
      • 1970-01-01
      • 2017-12-18
      相关资源
      最近更新 更多