S
S
Sport-code2019-05-17 07:24:21
MongoDB
Sport-code, 2019-05-17 07:24:21

Why does findOne() return undefined?

Hello!
I can’t understand, maybe someone has encountered such a problem,
why findOne () returns undefined?
When I just write lastOrder in the console, everything is fine (there is orderData and inside order: 3 )

module.exports.create = async (req, res) => {
    try {
        let lastOrder = await Order
            .findOne({user: req.user.id})
            // .sort({date: -1})
             console.log(lastOrder);

5cde358f70c09643624393.png
When I write lastOrder.orderData in the console, everything is fine (there is an order: 3 inside )
5cde36510aa6a042429619.png
And when I write lastOrder.orderData.order in the console , then undefined
5cde36b5c486e160662915.png
How can I get the order value ?
Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentin V., 2019-05-17
@Sport-code

orderData array, you need to specify the index
lastOrder.orderData[0].order

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question