【问题标题】:meteor mongodb limit return only id流星 mongodb 限制仅返回 id
【发布时间】:2015-10-27 14:59:05
【问题描述】:

我想限制从查询中获得的帖子数量

db.posts.find({});

我收到了所有帖子。我只想要前 10 个帖子,所以我已经这样做了。

db.posts.find({}, {limit: 10});

但不是有 10 个帖子,它只返回我所有帖子的 id

【问题讨论】:

  • 你让他们回到什么形式?只有_id 字符串的数组?或类似的东西:[{_id: "cZdWqpP4XsvWwCkva"},{_id: "mIxYfxadWZSc5JBdW"},...]?你怎么知道你只得到 id?

标签: mongodb meteor limit


【解决方案1】:

看起来您是在 mongo shell 中执行此操作,而不是直接在 Meteor 应用程序中执行此操作。两种环境之间的limit 语法略有不同:

Mongo shell (docs):

db.posts.find().limit( 10 )

流星js:

posts.find({},{limit: 10});

【讨论】:

    猜你喜欢
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    相关资源
    最近更新 更多