Javascript 使用mongoose和node获取不同的元素

Javascript 使用mongoose和node获取不同的元素,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我在mongo中有如下数据存储,其中集合名为\u,清单为 { "_id": "58a1ddcb8850c027298c4dc8", "name": "Listing 1", "description": "", "ticket": { "amount": 2, "type": "electronic", "splitType": 2, "seating": [ { "category": 1,

我在mongo中有如下数据存储,其中集合名为
\u,清单为

{   "_id": "58a1ddcb8850c027298c4dc8",   "name": "Listing 1",  
 "description": "",   "ticket": {
     "amount": 2,
     "type": "electronic",
     "splitType": 2,
     "seating": [
       {
         "category": 1,
         "section": 2,
         "row": 2
       },
       {
        "category": 3,
         "section": "uiui",
         "row": 33
       }
     ]   },   "metadata": {
     "user": {},
     "event": {},
     "venue": {}   },   "listingId": "aabb1cb6-4e79-4d48-9451-e5247230d397" }
我想从上面检索唯一的类别

这是我的密码

DBhelper.js

distinct: function (model, conditons, projection, options, distinctKey) {
            return new Promise(function (resolve, reject) {
                options = options || {};
                projection = projection || {};
                model.find(conditons, projection, options).distinct(distinctKey, function (error, data) {
                    if (error)
                        console.log("error is" + err);
                        reject(error);
                    console.log("data is " + data);
                    resolve(data);
                })
            })
        }
我调用上面的函数,如下所示

dbHelper.distinct(mongoose.model('_listing'), {}, {}, { 'ticket.seating.category': '1' }, 'ticket.seating.category', function (error, data) {
                console.log(data);
                callback(data);
            });

我无法在上面的方法中打印数据,而在dbhelper函数中打印数据。问题是什么?

DBHelper.js中的distinct函数返回一个承诺,您不是想将它用作
DBHelper.distinct(mongoose.model(''u listing'),{},{},{},{'ticket.seating.category':'1','ticket.seatch.category')。然后(函数(数据){console.log(数据);}
?@chridam不起作用,同样的问题它在distinct函数中抛出了一些错误吗?@RaviShankar没有抛出错误,我可以看到打印的数据