Monsieur Zartosht

Monsieur Zartosht

Who am I?

A very simple blog that belongs to a very simple full-stack web developer about his daily life and struggles through coding. here you will find many things such as music, movies, and code (lots of codes!)


What I write about


Recent Posts

Turn Mongoose Object into Plain Object

When getting a document out from mongo with mongoose client, the output is not of plain object type and it means you cannot easily use it inside template engines. I came across this problem and thought that couldn't use the output inside handlebars "each" helper.

Table of contents

    Turn Mongoose Documnet to Plain Javascript Object

    This is a really short blog post about turning Mongoose Document into a plain javascript object. for doing so all you need to do is add a lean() method after your find method:

    let post = findOne({
        _id: "ID"
    }).lean();

    And then pass this post object to your template engine. As a matter of fact, you can't find any difference between this to objects but some template engines such as handlebars can take the results count but not the properties out.

    I hope it helps.


    Posted in Express , Javascript , Mongo , Node js , Web on by

    Share this post: