keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.62k stars 2.21k forks source link

Integrate Distinct , limit and $ne in Keystone JS #4955

Open Rajivkumar1234 opened 5 years ago

Rajivkumar1234 commented 5 years ago

How do we integrate both distinct and selects the documents where the value of the field is not equal to the specified value.in a query in mongo using nodejs (keystone framework) ? or just basically in mongo. I am receiving an error which is field selection and slice cannot be used with distinct Error:. Any idea? or solution? I did try to use Syntax: {field: {$ne: value} } and that is the error. Also how can we include a limit when limit cannot be used with distinct Error: limit cannot be used with distinct.

Query ....

keystone.list('Customer').model.find({ customer_id: { $in: locals.data.customers } }, { vin: { $ne: vin } }).distinct('vin').limit(4) ....

I used aggregrate but it does not seem to work , any problelm with the syntax

db.customer.aggregate(
    { $match:{ customer_id: { $in: locals.data.customers } }},
    { $group:{_id:"$vin"}},
    { $skip: skip},
    { $limit: limit},
    { $group:{_id:null,vin:{$push:"$_id"}}}
);