草庐IT

followedIds

全部标签

mongodb - 仅从 mongo 集合中提取 ID

我只需要mongodb中集合中所有文档的ID。我正在使用meteor。现在,我正在使用基本的._each循环,但我敢打赌存在更好的方法,但不幸的是它没有点击我。下面是我的代码:varfollowedIds=Doubts.find({ch:chId,userId:userId}).fetch();vard_ids=[];_.each(followedIds,function(doubt){d_ids.push(doubt._id)}); 最佳答案 projection的小改动可以帮助您仅从集合中获取_ids:varfollowedId