2012-02-13 95 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

相关问题