.native()

.native() is only available when using Sails/Waterline with MongoDB.

Returns a raw Mongo collection instance representing the specified model, allowing you to perform raw Mongo queries.

For full documentation and usage examples, check out the native Node Mongo driver.

Note that sails-mongo maintains a single Mongo connection for each of your configured connections/datastores. Consequently, when using .native(), you don’t need to close or open db manually. For lower-level usage, you can require('mongodb') directly.

Example

  1. Pet.native(function(err, collection) {
  2. if (err) return res.serverError(err);
  3. collection.find({}, {
  4. name: true
  5. }).toArray(function (err, results) {
  6. if (err) return res.serverError(err);
  7. return res.ok(results);
  8. });
  9. });

Source: https://gist.github.com/mikermcneil/483987369d54512b6104

Notes

  • This method only works with Mongo! For raw functionality in SQL databases, use .query().