我正在使用Mongoose和Sails。我正在创建自己的ACL
,其中我的架构由processName
及其subprocesses
组成,其中subprocessName
分配了不同的permissions
,即READ
},WRITE
,ADMIN
和NA
。
我无法为我的数据库中的不同subprocess
保存相同的processName
。当我尝试执行下面给出的相同操作时,我收到以下错误
"name": "MongoError",
"message": "E11000 duplicate key error index:ACL.processnames.$subprocess.subprocessName_1 dup key: { : \"aaaa\" }",
"index": 0,
"code": 11000,
"errmsg": "E11000 duplicate key error index: ACL.processnames.$subprocess.subprocessName_1 dup key: { : \"aaaa\" }"
我的Schema
如下
{
processName: {
type: String,
required: true,
unique: true
},
subprocess: [{
subprocessName: {type:String},
permission: {
type: String,
enum: ["READ", "WRITE", "ADMIN","NA"],
default: "NA"
}
}]
}
我使用Node Insepector
并发现我的代码在.save
函数执行期间失败,如下所示
var db = require('../services/db.js'); //DB Connections
var ProcessName = mongoose.model('ProcessName');
var data = {};
data.processName = processName;
data.subprocess = subprocess;
var processes = db.ProcessName(data);
processes.save(processes, function (err, data) {
if (err) {
return res.json({
sucess: false,
exception: err
});
}
else {
return res.json({
sucess: true,
processDetail: data
});
}
});
我的样本数据在DHC上发布时遇到上述错误,如下所示
{
"processName":"wessssess LIkes",
"subprocess":[
{"subprocessName":"ssas","permission":"ADMIN"},
{"subprocessName":"aaaa","permission":"ADMIN"},
{"subprocessName":"aay"}
]
}
有人可以帮我解决这个问题吗?