我在尝试插入子文档时收到MongoDB错误.subdocs已经具有唯一的_id,但是对于我不想要唯一的不同的非唯一字段,会抛出错误.
Angular中的错误是:"Assets.serial已经存在". 如何使此字段包含重复值,以及导致模型假设它应该是唯一的?
这是我的Mongoose模型:
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var AssetUrlSchema = new Schema({
name: {
type: String,
unique: false,
default: '',
trim: true
},
url: {
type: String,
unique: false,
default: 'http://placehold.it/75x75',
trim: true
},
}),
AssetSchema = new Schema({
serial: {
type: Number,
unique: false
},
urls: {
type: [AssetUrlSchema],
unique: false,
default: [
{ name: '', url: 'http://placehold.it/75x75' },
{ name: '', url: 'http://placehold.it/75x75' }
]
}
}),
/**
* Item Schema
*/ …Run Code Online (Sandbox Code Playgroud)