C.Troffmann
C.Troffmann

Reputation: 3

Meteor How to get ONE element from MongoDB

In my MongoDatabase i have 5 elements.

First the _id then a follower with his idfollower and a following with his idfollowing.

now im trying to get only the IDFOLLOWING element

var userid = Relationships.findOne({follower: Meteor.user().username}).idfollowing;

this works!

Now i got 5 entries in the Database and the code only shows me 1 ID not 5

Upvotes: 0

Views: 81

Answers (1)

David Weldon
David Weldon

Reputation: 64342

Give this a try:

// 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');

Here's the documentation for:

Upvotes: 2

Related Questions