Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
  });
};

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!