簡體   English   中英

流星如何從MongoDB獲取一個元素

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM