您好我正在使用mongoosastic插件(elasticsearch.js的包装器)和mongoose.js。 简而言之,我有一个名为Event的模型,它具有声明为Game(模型名称)的子项(嵌套子文档)。更多Game将其他子项(嵌套子文档)声明为Result(模型名称)。所以,结果是游戏和游戏的孩子是事件的孩子。
所有这些属性都有一个名为nodeId的属性,该属性是唯一索引和必需的。 没有重复的nodeIds,我已经以编程方式检查了我的数据,所以我想知道我的模型声明是否有问题......
var ObjectSchema = new Schema({
key: {
unique: false,
index: false,
type: String,
es_indexed: true
},
value: {
unique: false,
index: false,
type: String,
es_indexed: true
}
});
var ResultSchema = new Schema({
odd: {
type: Number,
index: true,
es_indexed: true,
},
sortOrder: {
type: Number,
index: true,
es_indexed: true,
},
specialOddsValue: {
type: String,
index: true,
es_indexed: true
},
gameTypeResultsNr: {
type: Number,
index: true,
es_indexed: true,
},
startDate: {
type: Date,
index: true,
es_indexed: true,
es_type: "date"
},
nodeId: {
type: String,
required: true,
unique: true,
index: true,
es_indexed: true
},
parentNodeId: {
type: String,
required: true,
index: true,
es_indexed: true
},
localizedNames: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
localizedAdditionalValues: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
additionalValues: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
}
});
var GameSchema = new Schema({
gameTypeId: {
type: Number,
index: true,
es_indexed: true,
},
betTypeAvailability: {
type: Number,
index: true,
es_indexed: true,
},
eventNodeTypeId: {
type: Number,
index: true,
es_indexed: true,
},
startDate: {
type: Date,
index: true,
es_indexed: true,
es_type: "date"
},
nodeId: {
type: String,
required: true,
unique: true,
index: true,
es_indexed: true
},
parentNodeId: {
type: String,
required: true,
index: true,
es_indexed: true
},
localizedNames: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
localizedAdditionalValues: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
additionalValues: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
children: {
type: [ResultSchema],
index: false,
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
},
childrenCount: {
type: Number,
index: false,
es_indexed: false,
}
});
var EventSchema = new Schema({
_id: ObjectId,
eventNodeTypeId: {
type: Number,
index: true,
es_indexed: true
},
status: {
type: Number,
index: true,
es_indexed: true
},
startDate: {
type: Date,
index: true,
es_indexed: true,
es_type: "date"
},
_sport: {
type: ObjectId,
ref: "Sport",
es_schema: SportSchema,
es_indexed: true,
},
_league: {
type: ObjectId,
ref: "League",
es_schema: LeagueSchema,
es_indexed: true
},
_location: {
type: ObjectId,
ref: "Location",
es_schema: LocationSchema,
es_indexed: true
},
sportNodeId: {
type: String,
required: true,
index: true,
es_indexed: true
},
leagueNodeId: {
type: String,
required: true,
index: true,
es_indexed: true
},
locationNodeId: {
type: String,
required: true,
index: true,
es_indexed: true
},
nodeId: {
type: String,
required: true,
unique: true,
index: true,
es_indexed: true
},
parentNodeId: {
type: String,
required: true,
index: true,
es_indexed: true
},
isActive: {
type: Boolean,
index: true,
es_indexed: true
},
localizedNames: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
localizedAdditionalValues: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
additionalValues: {
localizedValues: {
type: [ObjectSchema],
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
},
participants: {
type: Array,
index: true,
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
},
children: {
type: [GameSchema],
index: false,
es_indexed: true,
es_type: "nested",
es_include_in_parent: true
}
});
我在导入时遇到的错误如下:
{ MongoError: E11000 duplicate key error collection: opap.events index: children.nodeId_1 dup key: { : null }
at Function.MongoError.create (D:\Development\xampp\htdocs\lab\praktorio\node-tools\importer\node_modules\mongodb-core\lib\error.js:31:11)
at toError (D:\Development\xampp\htdocs\lab\praktorio\node-tools\importer\node_modules\mongodb\lib\utils.js:139:22)
at D:\Development\xampp\htdocs\lab\praktorio\node-tools\importer\node_modules\mongodb\lib\collection.js:669:23
at handleCallback (D:\Development\xampp\htdocs\lab\praktorio\node-tools\importer\node_modules\mongodb\lib\utils.js:120:56)
at resultHandler (D:\Development\xampp\htdocs\lab\praktorio\node-tools\importer\node_modules\mongodb\lib\bulk\ordered.js:421:14)
at D:\Development\xampp\htdocs\lab\praktorio\node-tools\importer\node_modules\mongodb-core\lib\connection\pool.js:461:18
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
name: 'MongoError',
message: 'E11000 duplicate key error collection: opap.events index: children.nodeId_1 dup key: { : null }',
driver: true,
code: 11000,
index: 4,
errmsg: 'E11000 duplicate key error collection: opap.events index: children.nodeId_1 dup key: { : null }',
getOperation: [Function],
toJSON: [Function],
toString: [Function] }