Answer the question
In order to leave comments, you need to log in
Meteor.js: how to change the cursor (record) passed to the client?
Let's say there is a subscription that returns one specific record (cursor). There is a "nextPlayer" field, where the id of the user who goes next is indicated. But it is necessary that the nextPlayer field on the client has a value of either 0 (if the current client is walking) or 1 (if another is walking). So that the user id is not transmitted to the client. With what help it can be implemented?
Server code:
Meteor.publish('current-game', function(){
return Games.find({users: this.userId, finished: {$exists: false}}, {limit: 1})
})
Answer the question
In order to leave comments, you need to log in
Perhaps it is worth adding one more field to each document in Games, "a la" myTurn : 1
And in the publication, do this
Meteor.publish('current-game', function(){
let options = {limit: 1, fields: {myTurn: 0}}
const myTurn = Games.findOne({users: this.userId, nextPlayer: this.userId, finished: {$exists: false}}))
if (myTurn){
options.fields.myTurn=1
}
return Games.find({users: this.userId, finished: {$exists: false}}, {limit: 1})
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question