'return array undefined models controllers expressjs mongoose
I have this problem and I can't find the solution I want you to help me find the solution
the problem
I want to checkout all the books I added to the shopping cart
return array undefined
selle.model.js
/// file selle.model.js
const mongoose = require("mongoose");
// create url connect db
const url = "mongodb://localhost:27017/STOREBOOKS";
// create order in insert data
const order = mongoose.model("orders");
exports.getAllOrders = async (idUser) => {
return await mongoose
.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
return order.arguments([
{
$lookup: {
from: "books",
localField: "idBook",
foreignField: "_id",
as: "books",
},
},
{
$match: {
idUser: idUser,
},
},
]);
})
.catch((err) => {
console.log(err);
});
};
selle.controller.js
exports.getPageSelle = (request, response, next) => {
modelSelle.getAllOrders(request.session.userId).then((Orders) => {
console.log(Orders); // undefined
});
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
