在我的 MongoDatabase 中我有 5 个元素。
首先是 _id,然后是关注者及其 idfollower 和关注者及其 idfollowing。
现在我试图只获取 IDFOLLOWING 元素
var userid = Relationships.findOne({follower: Meteor.user().username}).idfollowing;
这有效!
现在我在数据库中有 5 个条目,代码只显示 1 个 ID,而不是 5
最佳答案
尝试一下:
// fetch an array of relationships where the current user is the follower
var selector = {follower: Meteor.user().username};
var relationships = Relationships.find(selector).fetch();
// create an array of ids? by extracting the idfollowing values from relationships
var userIds = _.pluck(relationships, 'idfollowing');
这是以下内容的文档:
关于javascript - Meteor 如何从 MongoDB 获取一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32049499/