Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31973

sometimes response doesn't display from the child collection if I connect to child collection inside parent collection.

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • ALL
    • Hide

      const viewAllReviews = (req, res, next) => {
          ParentTable.findOneById(req.params.id)
              .then((resp) => {
                  const r = resp;
                  if (resp.user_ratings.length > 0) {
                      for (let i = 0; i < resp.user_ratings.length; i += 1) {
                          ChildTable.findOneById(resp.user_ratings[i].userId)
                              .then((users) => {
                                  r.user_ratings[i] = {
                                      ratings: resp.user_ratings[i].ratings,
                                      comments: resp.user_ratings[i].comments,
                                      comment_added: resp.user_ratings[i].comment_added,
                                      comment_updated: resp.user_ratings[i].comment_updated,
                                      commentId: resp.user_ratings[i].commentId,
                                      userId: resp.user_ratings[i].userId,
       
                                      // data from user collection
                                      username: users.username,
                                      displayname: users.displayname,
                                      profilepicture: users.profilepicture
                                  };
       
                                  if (i === resp.user_ratings.length - 1) {
                                      res.result(resp.user_ratings, 200, next);
                                  }
                              });
                      }
                  } else {
                      res.result(r.user_ratings, 200, next);
                  }
              })
              .catch(e => next(e));
      };
      

      the result from user collection doesn't display sometimes. If I refresh again then it displays

      Show
      const viewAllReviews = (req, res, next) => { ParentTable.findOneById(req.params.id) .then((resp) => { const r = resp; if (resp.user_ratings.length > 0) { for (let i = 0; i < resp.user_ratings.length; i += 1) { ChildTable.findOneById(resp.user_ratings[i].userId) .then((users) => { r.user_ratings[i] = { ratings: resp.user_ratings[i].ratings, comments: resp.user_ratings[i].comments, comment_added: resp.user_ratings[i].comment_added, comment_updated: resp.user_ratings[i].comment_updated, commentId: resp.user_ratings[i].commentId, userId: resp.user_ratings[i].userId,   // data from user collection username: users.username, displayname: users.displayname, profilepicture: users.profilepicture };   if (i === resp.user_ratings.length - 1) { res.result(resp.user_ratings, 200, next); } }); } } else { res.result(r.user_ratings, 200, next); } }) .catch(e => next(e)); }; the result from user collection doesn't display sometimes. If I refresh again then it displays

    Description

      Hi,

      I am trying to display data from tow collection. I have connected to child(user) collection inside parent collection and fetching some basic details of user from user(child) collection and displaying along with parent collection data.
      The problem is sometimes data from user collection doesn't display. If I refresh the page again then it displays. sometimes displays, sometimes doesn't display. and if I refresh it displays. Checked in postman as well by calling API but same problem. sometimes response not displaying from user collection. But parent collection data displays every time.
      Can you please tell me how can I fix this.
      Please give me solution for this.

      Attachments

        Activity

          People

            mark.agarunov Mark Agarunov
            ashraf.seventech@gmail.com Ashraf Kamal
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: