Unable to fetch data after all data added to database in MONGODB,NODEJS

Viewed 28

Unable to fetch all the data after storing in the database, the below code returns empty but data is stored in the database

let cert;
let arr = [];
let insertedArray = [];
const request = https.request(options, async function (res) {
    cert = await res.socket.getPeerCertificate(true);
    do {
        arr.push(cert);
        cert = cert.issuerCertificate;
    } while (cert && typeof cert === 'object' && !arr.includes(cert));

    const promises = arr.map(async (i) => {
        insertedArray.push({ common_name: url, valid_from: i.valid_from, valid_to: i.valid_to, issuer: i.issuer.CN, serial: i.serialNumber, location: i.subject.C, organization: i.subject.O });
        await techstack.findByIdAndUpdate(techstackId, {
            $push: {
                sslDetails: insertedArray[0],
            },
        });
    });
    Promise.all(promises);
});
request.end();
const techstackDetails = await techstack.findById(techstackId);
return res.status(200).json({
    data: techstackDetails.sslDetails,
});
0 Answers
Related