MeteorJS: Users collection how to expose new field

I have added new field in user collection but when I access it in the client side Meteor.user().cart ( cart is my new field). Its undefined. How can expose new field (cart) so that it can be access in the client?

Answers:

Answer

The easiest way is to add a null publisher which will automatically send the data without the need for a subscription. Be sure to limit the fields to only the ones you need.

Meteor.publish(null, function() {
  return Meteor.users.find(this.userId, {fields: {cart: 1}});
});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.