Answer the question
In order to leave comments, you need to log in
What does the ._doc property mean in mongoose?
Here I want to send an array of orders objects to render. When "o"
has the "_doc" property, the code works, but I remove it and the object is lost.
res.render(`orders`, {
isOrders: true,
orders: orders.map(o => {
return {
...o._doc,
price: o.courses.reduce((total, c) => {
return total += c.count * c.course.price
}, 0)
}
})
Answer the question
In order to leave comments, you need to log in
with models it is necessary to work through api of these models.
To get data as a simple object, there is a toJSON method.
_doc should not be touched or used - this is internal data storage. Tomorrow update the lib and it may just disappear, or change as you like.
res.render(`orders`, {
isOrders: true,
orders: orders.map(o => {
return {
...o.toJSON(), // !! используйте вместо _doc
price: o.courses.reduce((total, c) => {
return total += c.count * c.course.price
}, 0)
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question