我正在try "使用Node.js与Express和Mongoose开发RESTful API"示例,但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" }',
模式定义中有一个独特的约束:
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 } });
我该怎么摆脱它呢?当我删除unique:true并重新启动应用程序时,架构不会得到更新.
mongodb如何处理模式的"变化"?