Py学习  »  MongoDB

MongoDB中limit()和$limit之间的差异

Mauricio Maroto • 4 年前 • 561 次点击  

在我的前端和认证用户后,我有以下代码可以工作: …

...
.then(authedUser =>
        db
          .collection('comments')
          .find({}, { limit: 1 })
          .asArray()
      )
      .then(doc => console.log('doc:', doc)); // 1 doc returned as array, yes!

但是,以下代码不起作用: .

...
.then(authedUser =>
        db
          .collection('comments')
          .find({})
          .limit(1)
          .asArray()
      )
      .then(doc => console.log('doc:', doc)); // error inside Promise, limit is not a function...

我能知道为什么吗?我知道limit()是一个游标方法,$limit是一个聚合阶段,所以现在我有点困惑了。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40226
 
561 次点击  
文章 [ 2 ]  |  最新文章 4 年前