Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 验证对象必须至少有一个运算符/meteor mongo_Mongodb_Meteor - Fatal编程技术网

Mongodb 验证对象必须至少有一个运算符/meteor mongo

Mongodb 验证对象必须至少有一个运算符/meteor mongo,mongodb,meteor,Mongodb,Meteor,我将一个方法写入一个集合的用户地址。然而,我不断得到错误: 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: fa

我将一个方法写入一个集合的用户地址。然而,我不断得到错误:

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事件:

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方法:

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)时,它会很好地打印出地址详细信息


有人能帮忙吗?提前谢谢你

请尝试以下代码:

Meteor.users.update(
  {$currUserId}, 
  {$addToSet:
    {'address.streetAddress': addressDetails.streetAddress,
     'address.city': addressDetails.city,
     'address.state': addressDetails.state,
     'address.zipCode': addressDetails.zipCode
    }
});

是的,那个错误让你走错方向了。无论如何,您在对象上使用的是
$addToSet
。这样做:

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

嗨-我仍然得到相同的“当修饰符选项为true时,验证对象必须至少有一个运算符。”错误:/i我认为我的语法很好。。架构可能有问题?