以下代码输出20 andural _id
的数据示例,以及我的集合中的 text
db.collection.aggregate({$sample: {size: 20}}, {$project: {"_id": 1,"text": 1}})
但是,我想要我收藏中的前20个样本中的_id
和text
,而不是20个随机样本( non-random (。
我将如何实现?
with aggregate
:
db.movies.aggregate([{$project: {"text": 1}}, {$limit:20}])
使用find
:
db.movies.find({}, {"text": 1}).limit(20)