4
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?

neelsg
  • 4,802
  • 5
  • 34
  • 58
user3736968
  • 85
  • 2
  • 5

2 Answers2

3

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

Shahriar
  • 13,460
  • 8
  • 78
  • 95
mdunisch
  • 3,627
  • 5
  • 25
  • 41
0

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.

Aurélien Thieriot
  • 5,853
  • 2
  • 24
  • 25