2

I am a meteor newbie, I am following this link from meteor guide to add more fields to Meteor.user document ,

 Template.CustomDataForm.events({
        "click [data-action='Customer/insert']": function (event) {
            event.preventDefault();
            var name = $('[name=name]').val();
            var email = $('[name=email]').val();
            var phone = $('[name=phone]').val();
            var address = $('[name=address]').val();
            const personalInfo = {
                Name: name,
                Email: email,
                Phone: phone,
                Address: address,
            };
           // I want to add personalInfo as a top-level field onto the user document
            Meteor.call('updateInfo',personalInfo);
         }
    });

Now on server side wrote Method to do Meteor.user.update with this passed info

 Meteor.methods({
           'updateInfo': function (newpersonalInfo) {
            console.log("Updating Info ..."+newpersonalInfo.Name+"  "+newpersonalInfo.Address+" "+Meteor.userId()) ;

            const proInfo = {
                Name: newpersonalInfo.Name,
                Email: newpersonalInfo.Email,
                Phone: newpersonalInfo.Phone,
                Address: newpersonalInfo.Address,
            };
            console.log("Updating for user "+Meteor.userId());
            Meteor.users.update(Meteor.userId(), {
                $set: {
                     personaInfo: proInfo
                }
            });
            console.log("After Updating"+Meteor.user());
        }
    });

Here is the Publication of Custom Data

Meteor.publish('Meteor.users.personalInfo', function ({ userIds }) {
  // Validate the arguments to be what we expect
  new SimpleSchema({
    userIds: { type: [String] }
  }).validate({ userIds });

  // Select only the users that match the array of IDs passed in
  const selector = {
    _id: { $in: userIds }
  };

  // Only return one field, `personalInfo`
  const options = {
    fields: { personalInfo: 1 }
  };

  return Meteor.users.find(selector, options);
});

Here is the Subscription

Template.profile.rendered = function () {
    Meteor.subscribe('Meteor.users.personalInfo',Meteor.userId());
    if (Meteor.user() && Meteor.user().personalInfo) {
        name = Meteor.user().profileInfo.Name;
        $('[id=profile-name]').val(name);
    }
}

But on Javascript console

Output of Meteor.user(); on Javascript console, I was expecting personalInfo as a toplevel field , but there is none,

enter image description here

On the Server side the log is

I20160528-11:04:27.725(5.5)? After Updating[object Object]

I couldn't seem to find out what is broken here ?

Thanks for reading my question

Update: Added Steps for Reproducing this issue

  • 1
    Hi I have added github repo [link] (https://github.com/vijaydasmp/CustomFieldDemo) repo which basically follows the meteor guide for adding custom data, but the custom data doesn't seem to get updated on Meteor.user document http://guide.meteor.com/accounts.html#custom-user-data – Vijay Manikpuri May 28 '16 at 14:08

0 Answers0