MongoDB: eindeutige Einschränkung entfernen
Ich versuche das Beispiel "Entwickeln einer RESTful-API mit Node.js mit Express und Mongoose" und habe ein Problem mit dem MongoDB-Schema festgestellt:
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" }',
Es gibt eine eindeutige Einschränkung in der Schemadefinition:
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 } });
Wie kann ich das loswerden? Wenn ich unique: true entferne und die App neu starte, wird das Schema nicht aktualisiert.
Wie geht Mongodb mit "Änderungen" des Schemas um?