MongoDB
 sql >> Base de données >  >> NoSQL >> MongoDB

Utiliser Async avec MongoDb pour remplir les documents de collection dans l'ordre

votre insertRowInBLD la fonction doit renvoyer une Promise instance au lieu de undefined comme maintenant. Async.series reçoit un tableau de undefined .

Ceci.

function fillBLD() {
    async.series(
        [
            insertRowInBLD('R01', 'Disclosure of data due to deliberate action by internal actor', 'E. Not significant', 'Partially effective', 'Low', '', '', '', ''),
            insertRowInBLD('R02', 'Corruption of data due to deliberate action by internal actor', 'E. Not significant', 'Partially effective', 'Low', '', '', '', ''),
            insertRowInBLD('R03', 'Unavailability of data due to deliberate action by internal actor', 'E. Not significant', 'Partially effective', '', '', '', '', ''),
            insertRowInBLD('R04', 'Disclosure of data due to attack of the communications link by internal/external actor', 'E. Not significant', 'Partially effective', 'Low', '', '', '', ''),
            insertRowInBLD('R05', 'Corruption of data due to attack of the communications link by internal/external actor', 'E. Not significant', 'Partially effective', 'Low', '', '', '', ''),
        ]
    );
}

est en fait ceci.

function fillBLD() {
    async.series(
        [
            undefined,
            undefined,
            undefined,
            undefined,
            undefined
        ]
    );
}