Created
May 8, 2014 21:55
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
}); | |
}); | |
} | |
}; | |
@Rafi993
const collection = await Promise.fromCallback(Model.native);
what are the methods that collection supports? because when I do collection.stats
It works but it throws an error for collection.serverStats
what's the meaning of collection.find({}, {
name: true
})?? collection is name of our collection? or Pet.native is for name of collection?
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
@Rafi993 I used this syntax: