Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikermcneil/483987369d54512b6104 to your computer and use it in GitHub Desktop.
Save mikermcneil/483987369d54512b6104 to your computer and use it in GitHub Desktop.
This works in Sails v0.10.0-rc7 (Waterline v0.10.0-rc12)
/**
* PetController
*
* @description :: Server-side logic for managing pets
* @help :: See http://links.sailsjs.org/docs/controllers
*/
module.exports = {
index: function (req,res) {
Pet.native(function(err, collection) {
if (err) return res.serverError(err);
collection.find({}, {
name: true
}).toArray(function (err, results) {
if (err) return res.serverError(err);
console.log('->',results);
return res.ok(results);
});
});
}
};
@cope
Copy link

cope commented Oct 21, 2020

what's the meaning of collection.find({}, {
name: true
})?? collection is name of our collection? or Pet.native is for name of collection?

Neither. Collection is the collection instance.

If your collection is called pet, then your model is most likely Pet. Then: Pet.native((err, petCollection) => { would probably be more clear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment