javascript - KeystoneJS - 创建新项目抛出重复键错误

标签 javascript mongodb mongoose keystonejs

我看到了一些与此相关的类似问题,但没有找到答案。

我正在尝试在我的 Keystone 项目中创建一个类似于帖子的画廊,其中将有一个画廊列表,其中包含一组选定图像的画廊:

var keystone = require('keystone'),
    Types = keystone.Field.Types;

/**
 * Gallery Model
 * =============
 */

var Gallery = new keystone.List('Gallery', {
    map: { name: 'name' },
    autokey: { path: 'slug', from: 'name', unique: true }
});

Gallery.add({
    name: { type: String, required: true},
    published: {type: Types.Select, options: 'yes, no', default: 'no', index: true},
    publishedDate: { type: Types.Date, index: true, dependsOn: { published: 'yes' } },
    description: { type: String },
    heroImage : { type: Types.Relationship, ref: 'Image' },
    images : { type: Types.Relationship, ref: 'Image', many: true }
});

Gallery.defaultColumns = 'title, published|20%, publishedDate|20%';
Gallery.register();

我能够成功创建一个画廊 - 但任何后续画廊都会抛出错误:

There was an error saving your changes: insertDocument :: caused by :: 11000 E11000 duplicate key error index: site-name.galleries.$key_1 dup key: { : null } (MongoError)

我不知道我需要对此模型进行哪些更改以允许我的画廊的独特 slug 直接链接到等。

最佳答案

从 MongoDB 中完全删除模型并重新启动。我通常在更改具有先前定义的索引的模型时看到此错误

关于javascript - KeystoneJS - 创建新项目抛出重复键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27284585/

相关文章:

mongodb - Mongodb聚合排序和限制组

node.js - Mongoose 查找并更新功能

javascript - 在选项卡上验证 `<input>`?

javascript - 如何在mongoDB中删除-nodejs

mongodb - replset 找不到具有 id 的 slave

mongodb - 为什么 Mongoose ObjectId.valueOf() 返回一个对象?

node.js - 推送在 mongoose/mongodb 数组中不起作用

javascript - 如何在 mongodb 模式中使用预定义值创建字段,并让用户使用单选按钮选择值

javascript - cloudant 服务器上的版本和库支持是什么?

c# - 使用 WSPBuilder 将 JavaScript、CSS 和其他内容添加到 WebPart