我尝试了“开发一个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的“变造”的模式?