Как сохранить следующий массив объекта в nodejs to mongodb?


0
export function _create(req) {
  let resourceID = req.body.resourceID;
  let resourcePrivilegeEntries = [];
  req.body.privilegeID.forEach(function (privilegeID, index) {
    resourcePrivilegeEntries.push({resourceID: resourceID, privilegeID: privilegeID})
  });
  return ResourcePrivilege.collection.insert(resourcePrivilegeEntries);
}

0
[
    {
        "_id": "5964ccebf80f382524a5b514",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "596363222bf14038f04d4efd"
    },
    {
        "_id": "5964ccebf80f382524a5b515",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "5963648b2bf14038f04d4f02"
    },
    {
        "_id": "5964ccebf80f382524a5b516",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "596364942bf14038f04d4f03"
    },
    {
        "_id": "5964ccebf80f382524a5b517",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "596364a02bf14038f04d4f04"
    }
]
Node.js, MongoDB,

node.js,mongodb,

-4

Ответов: 2


0
export function _create(req) {
  let resourceID = req.body.resourceID;
  let resourcePrivilegeEntries = [];
  req.body.privilegeID.forEach(function (privilegeID, index) {
    resourcePrivilegeEntries.push({resourceID: resourceID, privilegeID: privilegeID})
  });
  return ResourcePrivilege.collection.insert(resourcePrivilegeEntries);
}

0
[
    {
        "_id": "5964ccebf80f382524a5b514",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "596363222bf14038f04d4efd"
    },
    {
        "_id": "5964ccebf80f382524a5b515",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "5963648b2bf14038f04d4f02"
    },
    {
        "_id": "5964ccebf80f382524a5b516",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "596364942bf14038f04d4f03"
    },
    {
        "_id": "5964ccebf80f382524a5b517",
        "resourceID": "5963647f2bf14038f04d4f01",
        "privilegeID": "596364a02bf14038f04d4f04"
    }
]
Node.js, MongoDB,
Похожие вопросы