0

While trying other people solutions for this doesn't seem to fix this error for me. What I am trying to do is for each I in the array which my array comes from below

novel.ts

export let indexList = (req: Request, res: Response) => {
    novel.getAllDocuments((data) => {
        const novelObj = Convert.toNovelObj(data);

        res.render(`novels/all`, {
            title: `List of novels`,
            array: {
                name: novelObj.novelName,
                author: novelObj.novelAuthor,
                id: novelObj._id,
                img: novelObj.novelCoverArt,
                tags: novelObj.novelTags
            }
        });
    });
};

the novelObj converts my MongoDB from json to objects which can be seen below

RiNovel.ts

public getAllDocuments(callback: (data) => void) {
        var chapterInfoModel = mongoose.model('Novels', RiNovelcheme);
        chapterInfoModel.collection
            .find()
            .stream()
            .on('data', function(doc) {
                const novelObj = Convert.novelObjToJson(doc);
                return callback(novelObj);
            })
            .on('error', function(err) {
            })
            .on('end', function() {
            });
    } 

all.pug

each i in array
    p= i.name

the error is when there are multiple documents inside of my collection, how would I fix this

LoliLeague
  • 17
  • 3
  • this might be helpful https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client – pratRockss Mar 01 '19 at 05:42

1 Answers1

0

I figured it out it was my solution

export let indexList = (req: Request, res: Response) => {
    var chapterInfoModel = mongoose.model('Novels', RiNovelcheme);
    chapterInfoModel.find().exec((err, novel) => {
        if (err) {
            res.send(err);
        }
        res.render('novels/all', {
            title: 'All Novels',
            name: novel
        });
    });
};
LoliLeague
  • 17
  • 3