So I've looked around for .distinct function in waterline 0.10.x and have failed to find one, after looking on Stack Overflow I have found this...
How to extract distinct values from a mongo database using Waterline and Sails.js (version 0.10)?
Which ALMOST solved my problem.
So I tried looking at the native mongodb documentation and found that I can do this...
db.dogs.distinct('breed', { owner: ObjectId('123456') })
Which returns the distinct breeds that ObjectId('123456') has.
But this doesn't work...
Dog.native(function (err, collection){
collection.distinct('breed', { owner: '123456' }, function (err, breeds){
console.log(breeds);
});
});
This gives me an empty array.
I think the problem is that the .native function for Waterline doesn't understand when to cast the given string into an ObjectId and the Waterline documentation is still under-documented.
How would I get the distinct values with a query?