Want to find the next and previous object in relation to the current.
This is what I have
this.props._id = currentId;
data.video = Videos.findOne({_id: this.props._id});
data.next = Videos.findOne({votes: {$gte: data.video.votes}});
data.previous = Videos.findOne({votes: {$lte: data.video.votes}};
I know that this is not true, I’m sure that it will return objects, but it will not be the nearest object, and there is a chance that I will return the current object.
What I want to do is return the next or previous object, where my selector is voices, I also want to use Id to exclude the current object, then there is also a good chance that several objects will have the same number of votes.
It was 12 hours right now, and I’m almost going back to where I started, so I would really appreciate some examples to make me wrap my head around this, Not sure if I should use find or findOne.
VideoPage = React.createClass({
mixins: [ReactMeteorData],
getMeteorData() {
var selector = {};
var handle = Meteor.subscribe('videos', selector);
var data = {};
data.userId = Meteor.userId();
data.video = Videos.findOne({_id: this.props._id});
data.next = Videos.findOne({votes: {$gte: data.video.votes}});
data.previous = Videos.findOne({votes: {$lte: data.video.votes}};
console.log(data.video.votes);
console.log(data.video);
console.log(data.next);
console.log(data.previous);
return data;
},
getContent() {
return <div>
{this.data.video.votes}
<Youtube video={this.data.video} />
<LikeBox next={this.data.next._id} previous={this.data.previous._id} userId={this.data.userId} video={this.data.video} />
</div>
;
},
render() {
return <div>
{(this.data.video)? this.getContent() :
<Loading/>
}
</div>;
}
});