[英]Meteor How to get ONE element from MongoDB
在我的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');
這里是文檔:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.