title: Querying nested relations in Mongoosejs
body: <p>I have this relationship (not nested documents, an actual relationship with them by id) (the following is a GraphQL representation)</p>
  
  <pre><code>  appointment(id:"5aefada83ed11a4862ae908a") {
      _id
      location {
        _id
        name
        practice {
          _id
          name
        }
      }
    }
  </code></pre>
  
  <p>I was wondering what is the syntax for querying the <strong>appointment</strong> by <strong>practice</strong>. I have tried the following but no luck</p>
  
  <pre><code>return Appointment
  .findOne(_.pick(params, ["_id", "location.practice._id"]))
  .populate(_.keys(_.groupBy(_.reject(strapi.models.appointment.associations, {autoPopulate: false}), 'alias')).join(' '));
  </code></pre>
  
  <p>Where <code>params</code> is </p>
  
  <pre><code>{ _id: '5aefada83ed11a4862ae908a',
    'location.practice._id': 5aef661dca53d04354a36adc }
  </code></pre>
  
  <p>According to the nested documents docs, the dot syntax should work. Doing the same in a <code>where</code> clause doesn't seem to work either.
  Any ideas?</p>
  
  <p><strong>Update: Include the full example of the request (without trying to filter it by practice)</strong></p>
  
  <p>The document with its nested relations</p>
  
  <p>JSON of the appointment (using Robo 3T)</p>
  
  <pre><code>{
      "_id" : ObjectId("5aefada83ed11a4862ae908a"),
      "starts_at" : ISODate("2018-05-02T00:00:00.000Z"),
      "ends_at" : ISODate("2018-05-01T00:00:00.000Z"),
      "createdAt" : ISODate("2018-05-07T01:36:40.685Z"),
      "updatedAt" : ISODate("2018-05-07T01:36:54.780Z"),
      "__v" : 0,
      "id" : ObjectId("5aefada83ed11a4862ae908a"),
      "location" : ObjectId("5af52263900e1c1b1cc2374f"),
      "patient" : ObjectId("5aee7ee027d7e03b2e0c7c3b"),
      "doctor" : ObjectId("5aee1e6b7ae7d334d9247e79")
  }
  </code></pre>
  
  <p>JSON of the location (using Robo 3T)</p>
  
  <pre><code>{
      "_id" : ObjectId("5af52263900e1c1b1cc2374f"),
      "name" : "Ottawa",
      "createdAt" : ISODate("2018-05-11T04:56:03.024Z"),
      "updatedAt" : ISODate("2018-05-11T04:56:57.932Z"),
      "__v" : 0,
      "id" : ObjectId("5af52263900e1c1b1cc2374f"),
      "practice" : ObjectId("5aef661dca53d04354a36adc")
  }
  </code></pre>
  
  <p>JSON of the practice (using Robo 3T)</p>
  
  <pre><code>{
      "_id" : ObjectId("5aef661dca53d04354a36adc"),
      "name" : "Demo",
      "email" : "demo@odonto.me",
      "createdAt" : ISODate("2018-05-06T20:31:25.456Z"),
      "updatedAt" : ISODate("2018-05-06T20:31:25.469Z"),
      "__v" : 0,
      "id" : "5aef661dca53d04354a36adc"
  }
  </code></pre>
  
  <p>The queries happening on the background when querying this model</p>
  
  <pre><code>Mongoose: users-permissions_user.findOne({ _id: ObjectId("5aee1e6b7ae7d334d9247e79") }, { fields: {} })
  Mongoose: users-permissions_role.find({ _id: { '$in': [ ObjectId("5aedd8b3e235fa32d54c7b63") ] } }, { fields: {} })
  Mongoose: appointment.find({ staff: { '$in': [ ObjectId("5aee1e6b7ae7d334d9247e79") ] } }, { fields: {} })
  Mongoose: practice.find({ _id: { '$in': [ ObjectId("5aef661dca53d04354a36adc") ] } }, { fields: {} })
  Mongoose: users-permissions_permission.findOne({ role: ObjectId("5aedd8b3e235fa32d54c7b63"), type: 'application', controller: 'appointment', action: 'findone', enabled: true }, { fields: {} })
  Mongoose: appointment.findOne({ _id: ObjectId("5aefada83ed11a4862ae908a") }, { fields: {} })
  Mongoose: patient.find({ _id: { '$in': [ ObjectId("5aee7ee027d7e03b2e0c7c3b") ] } }, { fields: {} })
  Mongoose: location.find({ _id: { '$in': [ ObjectId("5af52263900e1c1b1cc2374f") ] } }, { fields: {} })
  Mongoose: location.findOne({ _id: ObjectId("5af52263900e1c1b1cc2374f") }, { fields: {} })
  Mongoose: practice.findOne({ _id: ObjectId("5aef661dca53d04354a36adc") }, { fields: {} })
  [2018-05-14T01:51:09.117Z] debug POST /graphql?_id=5aefada83ed11a4862ae908a (32 ms)
  </code></pre>