MongoDB的:删除唯一约束(MongoDB: remove unique constraint)

2019-06-28 01:57发布

我尝试了“开发一个RESTful API如何使用Node.js随着Express和猫鼬”的例子,我跑了与MongoDB的架构问题:

POST: 
{ title: 'My Awesome T-shirt 2',
  description: 'All about the details. Of course it\'s black.',
  style: '12345' }
{ [MongoError: E11000 duplicate key error index: ecomm_database.products.$style_1  dup key: { : "12345" }]
  name: 'MongoError',
  err: 'E11000 duplicate key error index: ecomm_database.products.$style_1  dup key: { : "12345" }',

有在架构定义的唯一contraint:

var Product = new Schema({  
    title: { type: String, required: true },  
    description: { type: String, required: true },  
    style: { type: String, unique: true },  
    modified: { type: Date, default: Date.now } });

我该如何摆脱掉了吗? 当我删除独特:真正并重新启动应用,架构没有更新。

如何处理mongodb的“变造”的模式?

Answer 1:

“如何处理的mongodb‘变造’的模式?”

MongoDB是无模式

有唯一性的唯一的事情是执行上的索引级别在那里你可以用独特的标准集合定义索引。 所以,你可能需要删除相关的指数,如果需要重新创建它。



文章来源: MongoDB: remove unique constraint