Home > Mobile >  Modifying mongoose result modifies all document instead of one
Modifying mongoose result modifies all document instead of one

Time:11-22

I have this function:

const getXNumberOfDocuments = async function getXNumberOfDocuments(
  page,
  results_per_page
) {
  /*************************************************** */
  results_per_page = parseInt(results_per_page);
  let x_number_of_documents = await Document.find()
    .populate([
      {
        path: "user",
        populate: {
          path: "profile",
          select: ["profileImageURL"],
        },
      },
    ])
    .limit(results_per_page)
    .skip(results_per_page * page)
    .lean();
  /*************************************************** */
  // I will stop this loop at i=0 by throwing an error
  // As you se below
  for (let i = 0; i < x_number_of_documents.length; i  ) {
    console.log("           
  • Related