Mongo 和节点 js 对 return 的查询,没有重复,不同

Mongo and node js a query to return with no duplicates , distinct

我们如何在 mongo 中查询结果不会重复的地方,我试过使用 distinc 但它似乎不起作用。

查询

keystone.list('Customer').model.find().sort('name').where('vin').in([vin]).exec(

function (err, results) {

    if (err || !results.length) {
        return next(err);
    }
    .....    
keystone.list('Customer').model.find().distinct('customer_id')
  .where('fieldName', 'fieldValue')
  .exec(function(err, result) {
    //array of _ids
  });

然后在 $in 查询中传递所有 id 以获取所有记录。