Hy,
I’m developing a game where each one can play more than once, and his scores are saved in server;
what I want to do is to print only the most recent score of each player. I did something like that ( see the code below) but seem not working properly;
like you can see in the picture below; it print two scores of player"abdou"; but i want that it print only the recent one of each player
the function in publication.js
Meteor.publish(‘PlayersList’, function(){
// return PlayersList.find({}, {sort: {score: 1, name: 1}, limit:50 });
// return PlayersList.find({}, {sort: { age: -1 } });
return PlayersList.find({}, {sort: {date_created: -1}});
});
methods of collection
Meteor.methods({
‘add_player’: function(h,player,j){
PlayersList.insert({
name: h,
score: player,
userId: j,
date_created: new Date().getTime()
});
},
'remove_player': function(h,player,j){ PlayersList.remove({ name: h, score: player, userId: j // date_created: date }); }, 'update_player': function(player){ PlayersList.update({ name: 'player', score: player }); }
});
PlayersList = new Mongo.Collection(‘players’);
edit:
To make the things more clear
in my collection I ve some thing like that ( just an example)
{name:‘A’,score: 2, date: 4456546}
{name:‘A’,score:33, date:3453454}
{name:‘A’,score:34, date: 3453}
{name:‘A’,score:0, date: 12334}
{name:‘B’,score: 2, date: 4456546}
{name:‘B’,score:33, date:3453454}
{name:‘B’,score:34, date: 3453}
{name:‘B’,score:0, date: 12334}
{name:‘C’,score: 2, date: 4456546}
{name:‘C’,score:33, date:3453454}
{name:‘C’,score:34, date: 3453}
{name:‘C’,score:0, date: 12334}
and what I want is some thing like this ( the very recent score of each ):
{name:‘A’,score: 2, date: 4456546}
{name:‘B’,score: 2, date: 4456546}
{name:‘C’,score: 2, date: 4456546}
I’m thinking for cloning the the old collection and deal with the results and put it in new one;
any help please!! I’m newbie