keystone-classic icon indicating copy to clipboard operation
keystone-classic copied to clipboard

Integrate Distinct , limit and $ne in Keystone JS

Open Rajivkumar1234 opened this issue 5 years ago • 0 comments

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"}}}
);

Rajivkumar1234 avatar Aug 09 '19 02:08 Rajivkumar1234