Я новичок в узле js и пытаюсь вставить несколько строк в mognodb, используя экспресс js из нефрита:
Я хочу добавить модульный доступ для пользователя к базе данных, например (pfa) :
Для этого у меня есть форма мопса:
расширяет макет
блок контента
h1 = название
form(method='POST' action='/role/update_role_access')
div.form-group.col-md-8
label(for='role') Role:
select#role.form-control(type='select', placeholder='Select role' name='role' required='true' )
for role_nm in role_list
option(value=role_nm._id) #{role_nm.role}
table(class='table table-striped')
thead.thead-dark
tr: th Module
th Read Only
th Read and Write
th Full Access
tbody
- var j=1
for modules_nms in modules_nm
tr: td #{modules_nms.module_name}
input(type='hidden' name='module_nm'+j value=modules_nms._id id=module_nm)
- for(var i = 1; i < 4; i++)
td
input(type='radio' name='access'+j value=i id=i)
- j++
div.form-group.col-md-8
button.btn.btn-primary (type = 'submit') Применить
Контроллер для сохранения нескольких данных с одинаковым именем
roleController.role_access_update_post = function (req, res, next) {
var role_acc = [{role_id: req.body.role, модуль: req.body.module_nm, access_type: req.body.access}];
RoleAccess.collection.insert(role_acc, function (err, docs) {
if (err){
return console.error(err);
} else {
console.log("Multiple documents inserted to Collection");
}
});
};