inProgress-team / react-native-meteor

Meteor Reactivity for your React Native application :)
MIT License
693 stars 210 forks source link

Proper way to pass parameters from client to server #339

Open Steve1820 opened 5 years ago

Steve1820 commented 5 years ago

Hey guys,

I've been struggling with this for days. I have my server set up as:

Meteor.publish('quests_filtered', (id) => { return Quests.find({'_id': id}); });

And my client like the below. You can think of quests exactly like a to do list.

export default withTracker(params => { Meteor.subscribe('quests_filtered', params.id); return { quests: Meteor.collection('quests_filtered').find({'_id': id}), }; })(QuestFeed);

The collection is defined as:

const Quests = new Mongo.Collection('quests');

However this.props.quests in the client side still returns the whole Quests collection and not those filtered by id.

I am at a complete loss - any ideas?

Nauzer commented 5 years ago

In your publish query there is _id and in your client query there is id. Guess that could cause some discrepancy.

Steve1820 commented 5 years ago

@Nauzer Thanks I updated my post and fixed it in my code but the problem still persists.

Is it working in your projects?

Nauzer commented 5 years ago

Haven't used the library in a while... but I think so.

On the client you should query 'quests' collection, not the publication name. Meteor.collection('quests').find({'_id': id})

Do you have 'autopublish' turned off on your Meteor server?

Steve1820 commented 5 years ago

I dont have autopublish turned off - will this affect behaviour?

Apologies for being an absolute noob.

Steve1820 commented 5 years ago

@Nauzer thanks it worked!!!