Ich versuche, mehrere ‚Gruppen‘ in einer Gruppe Sammlung mit insertMany, aber es (s immer Anheben einen Fehler nach dem ersten Artikel einfügen eingefügt wird ..mongodb: Fehler mit insertMany
>db.groups.insertMany([{"name":"GroupA","description":"Description GroupA"},
{"name":"GroupB","description":"Description GroupB"},
{"name":"GroupC","description":"Description GroupC"}])
erste Element
{ "_id" : ObjectId("593ad787da6a6eba2994dfb6"), "name" : "GroupA",
"description" : "Description GroupA" }
Fehler
2017-06-09T19:14:47.537+0200 E QUERY [thread1] BulkWriteError: write error at item 1 in bulk operation :
BulkWriteError({
"writeErrors" : [
{
"index" : 1,
"code" : 11000,
"errmsg" : "E11000 duplicate key error collection: cockpit-api-test.groups index: roles.name_1 dup key: { : null }",
"op" : {
"_id" : ObjectId("593ad787da6a6eba2994dfb7"),
"name" : "GroupB",
"description" : "Description GroupB"
}
}
],
"writeConcernErrors" : [ ],
"nInserted" : 1,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
[email protected]/mongo/shell/bulk_api.js:372:48
BulkWriteResult/[email protected]/mongo/shell/bulk_api.js:336:24
Bulk/[email protected]/mongo/shell/bulk_api.js:1173:1
[email protected]/mongo/shell/crud_api.js:302:5
@(shell):1:1
eingefügt
was ist los? Dank für Feedback
Gruppenmodell
/**
* Role Schema
*/
const RoleSchema = new Schema({
name: { type: String, unique: true, required: true },
description: { type: String, required: false, trim: true, },
createdAt: { type: Date, default: Date.now }
});
/**
* Group Schema
*/
const GroupSchema = new Schema({
name: { type: String, unique: true, required: true },
description: { type: String, required: false, trim: true, },
roles: [RoleSchema],
createdAt: { type: Date, default: Date.now }
});
vielen Dank ... guter Punkt. der role.name benötigt: true ist schuldig! – erwin