验证对象必须至少具有一个操作员/流星蒙哥 [英] Validation object must have at least one operator / meteor mongo

查看:45
本文介绍了验证对象必须至少具有一个操作员/流星蒙哥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为集合的用户地址编写了一个方法.但是,我不断收到错误消息:

I wrote a method to a user's address to a collection. However, i keep getting the error:

When the modifier option is true, validation object must have at least one operator.

这是我的模式:

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);

这是我的addAddress事件:

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');
  }
});
},
});

这是我的addAddress方法:

Here's 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
        }
    });
}
});

注意-当我执行console.log(addressDetails)时,它会很好地打印出地址详细信息.

Note - when I do console.log(addressDetails), it prints out the address details just fine.

有人可以帮忙吗?预先谢谢你!

Can someone help? Thank you in advance!!

推荐答案

是的,该错误会导致您向错误的方向发送信息.无论如何,您在对象上使用$addToSet.这样做:

Yeah, that error kinda sends you in the wrong direction. Regardless, you're using $addToSet on an object. Do this:

Meteor.users.update(currentUserId, {$set: addressDetails.address}

这篇关于验证对象必须至少具有一个操作员/流星蒙哥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆