我使用MongoDB Node.js原生驱动程序版本2.2.29遇到了问题。
这是我正在运行的代码:
let cursor = db.collection( 'log' )
.find({timestamp: { '$lte': 1498556839 }})
.sort( { create_date_ttl: -1 } )
.limit( 3 );
如果我现在运行
cursor.count()
并处理Promise,我发现计数给了我56个记录,而不是3个(指定的限制)。cursor.count().then( (count) => {
// count here is 56
});
然而,如果我使用回调函数运行
cursor.count( function (err, count) {})
,则只有3条记录的计数是正确的。cursor.count( function (err, count) {
// count here is 3 according to the limit specified.
});
有人遇到同样的问题吗?或者有人可以解释一下这是怎么可能的吗?也许我漏掉了什么,但根据官方文档documentation,似乎没问题。
提前感谢。
.sort()
和.limit()
修饰符的 bug。 - Neil Lunn