mongodb - Update extended Meteor.user collection -
i have extended meteor-collection2 user profile
user profile
/// --- user profile --- /// userprofile = new mongo.collection("userprofile"); schema.userprofile = new simpleschema({ username: { type: string, optional: true }, usergender: { type: string, allowedvalues: ['male', 'female'], optional: true }, userage: { type: number, optional: true, regex: /^[0-9]{2}$/ }, userweight: { type: number, decimal: true, optional: true }, usergrowth: { type: number, optional: true }, userexpirience: { type: number, optional: true }, useravatarid: { type: string, optional: true }, profilecomplete: { type: boolean, optional: true } }); userprofile.attachschema(schema.userprofile);
user
/// --- user --- /// schema.user = new simpleschema({ username: { type: string, regex: /^[a-z0-9a-z_]{3,15}$/ }, emails: { type: [object] }, "emails.$.address": { type: string, regex: simpleschema.regex.email }, "emails.$.verified": { type: boolean }, createdat: { type: date }, profile: { type: schema.userprofile, optional: true }, services: { type: object, optional: true, blackbox: true }, // add `roles` schema if use meteor-roles package. // option 1: object type // if specify type object, must specify // `roles.global_group` group whenever add user role. // example: // roles.adduserstoroles(userid, ["admin"], roles.global_group); // can't mix , match adding , without group since // fail validation in cases. roles: { type: object, optional: true, blackbox: true }, // option 2: [string] type // if sure never need use role groups, // can specify [string] type roles: { type: [string], optional: true } }); meteor.users.attachschema(schema.user);
but can't update property of user, example useage. when try it:
meteor.users.update({_id: userid}, {$set: {userage: 30}}, {validate: false});
it destroy data of user , collection contain id
and second question: how can retreave data user profile ex age?
you overwriting entire content of user instead of userage in profile. think small change below fix problem:
meteor.users.update({_id: userid}, {$set: {profile.userage: 30}}, {validate: false});
i'm not sure mean "ex age", history of age?
Comments
Post a Comment