MongoDB:删除唯一的约束

我正在尝试“用Express和Mongoose开发使用Node.js的RESTful API”的例子,我遇到了一个MongoDB Schema的问题:

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" }', 

模式定义中有一个独特的约束:

 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如何处理“改变”模式?

“mongodb如何处理”改变“模式?

MongoDB是无模式的

唯一性的唯一实现是在索引级别,您可以使用唯一条件在集合上定义索引。 所以你可能想删除相关的索引,并在必要时重新创build它。