更新属性工作不正常Meteor/MongoDB
Updating attribute not working properly Meteor / MongoDB
我正试图通过单击按钮来更新文档。然而,我不断收到一条"内部错误"的消息。我试图更新的文档被称为"已确认",它可以取true/false值。
这是我的methods.js
:
Meteor.methods({
'confirmUser1': function(currUserId) {
var currentUserId = currUserId;
Meteor.users.update(currentUserId, {$set:
{
'confirmed': true
}
});
console.log('user verified!');
}
});
这是我的模板事件助手:
Template.Users.events({
'click .confirmUser': function(e, tmpl) {
e.preventDefault();
var currentUserId = this._id;
Meteor.call('confirmUser1', currentUserId, function(error) {
if (error) {
alert(error.reason);
} else {
console.log('success!');
Router.go('Admin');
}
});
}
});
我的按钮:
<p><button class="confirmUser">Confirm User</button></p>
注意:我在不同的更新按钮/方法中使用了与此非常相似的代码,效果很好。。。所以我不确定这里发生了什么。
尝试使用Meteor.userId();
,事件处理程序中的上下文与在Template.helper
中使用的上下文截然不同
如果你做console.log(currentUserId)
,你应该得到未定义。
所以改变这个
var currentUserId = this._id;
对此。
var currentUserId = Meteor.userId();
相关文章:
- 无法在Meteor/MongoDB中返回当前用户对象
- 更新属性工作不正常Meteor/MongoDB
- 如何从Meteor内部获取当前连接的MongoDB数据库的URL
- 如何在MongoDB和Meteor中自动销毁1-M连接
- Meteor:从Twilio获取SMS文本列表,并将它们插入mongoDB
- Selectize.js:如何将数据库中已经选择的标签预加载到输入字段(Meteor&MongoDB/JSON)
- 我的 Meteor 项目如何通过服务器端 MongoDB/集合查找查询可靠地显示信息
- MongoDB 无法将$addToSet应用于 Meteor JS 中的非数组
- Meteor+MongoDB:如何获取嵌套数据
- MongoDB:$addToSet Meteor中的重复结果回调
- 使用Meteor将图像写入/读取到MongoDB中
- 使用Meteor.js使用多个Mongodb数据库
- 处理 Meteor 和 mongodb 中的嵌套字典
- Meteor - 将 mongodb 查询分配给变量并将其插入到另一个集合
- 在 meteor 中使用 MongoDB 聚合时无法获得正确的结果
- MongoDB & Meteor - 推送到嵌套数组的查询不起作用,没有抛出错误
- 更新数组MongoDB Meteor内部的对象
- MongoDB/Meteor:为每个数组元素添加唯一的ID
- 在MongoDB/Meteor中使用elemMatch查找嵌套数组数据
- Mongodb /meteor收集检查子文档字段是否存在,当字段是一个变量