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

Sample of three or more collections

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Environment:
      PHP driver

      Hello!

      There are collections

      city:

      {"_id", "name"}

      company:

      {"_id", "name", "cityID"}

      comments:

      {"_id", "text", "companyID"}

      You must select the last 10 comments on companies of a certain city.

      Now I select _id first of all companies in the city, and then the 10 comments received on _id
      Here's the code:

      $ db-> execute ('function () {

      var result = {};

      var company = [];
      result.company = [];
      db.company.find (

      {"city": "msk"}

      ,

      {"title": 1, "_id": 1}

      ). forEach (function (a) {
      result.company [a._id] = Object.deepExtend (a, result [a._id]);
      company.push (a._id);
      });

      var comments = [];
      result.comments = [];
      db.comments.find ({"company": {"$ in": company}}). sort (

      {"createTime": -1}

      ). limit (10). forEach (function (a)

      { result.comments [a._id] = Object.deepExtend (a, result [a._id]); comments.push (a._id); }); return result; }

      ');

      Esti's a better option to do what I need?
      Thanks in advance for your advice!

            Assignee:
            sam.helman@10gen.com sam.helman@10gen.com
            Reporter:
            jeka5555 Evgeny Kalibrov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: