Reputation: 85
Model.distinct("Age").done(function(err, ward) {
if(err)
return next(err);
if(!ward)
return next();
res.json(ward);
});
After executing this code, it gives the following error:
TypeError: Object [object Object] has no method 'distinct'
But distinct works in robomongo. How can I rectify the error?
Upvotes: 4
Views: 2794
Reputation: 3697
Currently Walterline (the ORM of sails) dont support distinct()-function.
But you can use the native()-function to get direct access to the native mongo driver:
Modelname.native(function(err,coll){
coll.distinct("Age", function(err,result){
res.json(result);
});
});
See: https://sailsjs.com/documentation/reference/Models/Model-Methods/native.html
Upvotes: 3
Reputation: 5923
What you probably need is the ability for the SailsJS ORM (Waterlin) to give you back the native MongoDB collection: http://beta.sailsjs.org/#/documentation/reference/Models/Model-Methods/native.html
Once you've got it you will be able to call native MongoDB queries.
By design, Waterline is meant to be used with several databases while keeping the same code. And currently there is no "disctinct" feature.
Upvotes: 0