2012-02-13 125 views
0

我想我的mongoose查詢回調結果從mongodb只包含文檔的某個部分。現在,下面的代碼返回整個文檔,而不僅僅是假定的切片數組部分。任何線索爲什麼?在數據庫中,掛起實際上包含多於10個元素。謝謝貓鼬,返回整個文檔,而不僅僅是它的一部分

var NotificationsReference = new Schema({ 

    id    : Number, //fbid 
    unRead   : Number, 
    pendingSize : Number, 
    pending  : [Notification] 

}); 

NotificationsReference.find({ id: userId}, { pending: { $slice: [skip, 5]}}, function(err, result){ 
        if(err || result === null){ 
         callback("Failed"); 
        } 
        else{ 
         callback(result); 
        } 
       }); 

回答

2

嘗試使用該API貓鼬:

NotificationsReference 
    .findById(userId) 
    .where('pending') 
    .slice([skip, 5]) 
    .run(function(err, docs){ 
     console.log(err ? err : docs); 
    }) 
+0

貓鼬3.X現在使用的,而不是.RUN .exec:http://mongoosejs.com/docs/migration.html – 2013-12-26 19:35:27

相關問題