I wrote a method for the user address in the collection. However, I keep getting the error:
When the modifier option is true, validation object must have at least one operator.
Here is my diagram:
var Schemas = {}; Schemas.UserAddress = new SimpleSchema({ streetAddress: { type: String, max: 100, optional: false }, city: { type: String, max: 50, optional: false }, state: { type: String, regEx: /^[a-zA-Z-]{2,25}$/, optional: false }, zipCode: { type: String, regEx: /^[0-9]{5}$/, optional: false } }); Schemas.User = new SimpleSchema({ emails: { type: [Object], optional: false }, "emails.$.address": { type: String, regEx: SimpleSchema.RegEx.Email }, "emails.$.verified": { type: Boolean }, createdAt: { type: Date }, profile: { type: Schemas.UserProfile, optional: false }, address: { type: Schemas.UserAddress, optional: false }, services: { type: Object, optional: true, blackbox: true } }); Meteor.users.attachSchema(Schemas.User);
And here is my addAddress event:
Template.editAddress.events({ 'click .addAddress': function(e, tmpl) { e.preventDefault(); var currentUserId = this._id; var addressDetails = { address: { streetAddress: $('#streetAddress').val(), city: $('#city').val(), state: $('#state').val(), zipCode: $('#zipCode').val() }, }; console.log(addressDetails); Meteor.call('addNewAddress', addressDetails, currentUserId, function(error) { if (error) { alert(error.reason); } else { console.log('success!'); Router.go('Admin'); } }); }, });
Here is my addAddress method:
Meteor.methods({ 'addNewAddress': function(addressDetails, currUserId) { var currentUserId = currUserId; Meteor.users.update(currentUserId, {$addToSet: {'address.streetAddress': addressDetails.streetAddress, 'address.city': addressDetails.city, 'address.state': addressDetails.state, 'address.zipCode': addressDetails.zipCode } }); } });
Note. When I do console.log (addressDetails), it accurately displays the address data.
Can anyone help? Thanks in advance!