H
H
hollanditkzn2017-12-29 11:15:35
Node.js
hollanditkzn, 2017-12-29 11:15:35

How to change the array that came from mongoose?

I can’t get it out, which I have changed now, writes that

TypeError: doc.map is not a function

Here is how I implemented
.get('/order/:id', async(ctx) => {
        try {
            let order = await Order.findOne({orderId: ctx.params.id}).exec((err, doc) => {
                doc.time = moment(doc.createdAt).local('ru').format('DD MMMM YYYY H:mm');
                return doc;
            });
            console.log(order);
            await ctx.render('order_view', {order});
        } catch(err) {
            await console.log(err);
        }
    })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-12-29
@hollanditkzn

Are you sure the array comes from Mongo? judging by the request comes the object.
And you don't have to use await here ctx.render('order_view', {order}); and here console.log(err);
If you need an array then use this query
and then do whatever you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question