Differs in js and mongodb sails

Model.distinct("Age").done(function(err, ward) {
  if(err)
    return next(err);
  if(!ward)
    return next();
  res.json(ward);
});

After executing this code, it throws the following error:

TypeError: Object [object Object] has no method 'distinct'

But different jobs in robomongo. How to fix the error?

+4
source share
2 answers

Currently, Walterline (ORM Sails) does not support the distinct () function -

But you can use the native () function to directly access the mongo native 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

+3
source

, SailsJS ORM (Waterlin) MongoDB: http://beta.sailsjs.org/#/documentation/reference/Models/Model-Methods/native.html p >

, MongoDB.

Waterline . "" .

0

Source: https://habr.com/ru/post/1544435/


All Articles