title: MongoDB aggregation on Loopback
body: <p>How do I obtain the sum of a Loopback PersistedModel?</p>
  
  <p>There does not seem to be a <a href="http://apidocs.strongloop.com/loopback/#persistedmodel-find" rel="nofollow">documentation</a> on how to achieve that. </p>
  
  <p>If possible I would like to avoid having to find all the rows and sum it in Node.js.</p>
  
  <h3>UPDATE</h3>
  
  <p>Trying out the example from <a href="https://github.com/strongloop/loopback/issues/890" rel="nofollow">https://github.com/strongloop/loopback/issues/890</a></p>
  
  <pre><code>var bookCollection = Book.getDataSource().connector.collection(Book.modelName);
  </code></pre>
  
  <p>I got an error</p>
  
  <pre><code>throw new Error('MongoDB connection is not established');
  </code></pre>
  
  <p>How do I get a handle on the collection to manually run aggregate query on a MongoDB collection?</p>