流星收集更新不是在更新文档
meteor collection.update is not updating document
我正试图在客户端方法中触发更新(考虑稍后进入服务器),如下所示:
Meteor.methods({
// Calling this and passing in a currentSelected value = "avatar" on click
'updateSelectedDocument' : function(currentSelected) {
var current = LayoutVariations.findOne({elementID: currentSelected});
var index = current.currentIndex;
myCollection.update({_id :current._id}, {currentIndex: 2});
}
});
.update应该找到文档并更新该文档的currentIndex属性,该属性是一个整数。
我在控制台中通过传递_id(例如"GRvujvgBEmem3Dp3d")运行了myCollection.update({_id :current._id}, {currentIndex: 2});
,它就工作了。当我在方法中调用它时,它不会更新,也不会抛出任何错误。
想知道问题出在哪里。
在更新中使用$set
运算符将字段currentIndex
的值替换为指定的:
Meteor.methods({
// Calling this and passing in a currentSelected value = "avatar" on click
'updateSelectedDocument' : function(currentSelected) {
var current = LayoutVariations.findOne({elementID: currentSelected});
var index = current.currentIndex;
myCollection.update({_id :current._id}, {$set: { currentIndex: 2 } }, function(error, affectedDocs) {
if (error) {
throw new Meteor.Error(500, error.message);
} else {
return "Update Successful";
}
});
}
});
相关文章:
- 流星收集更新不是在更新文档
- MongoDB findAndModify:>>>查找和更新文档数组中的对象
- Javascript 不会在浏览器中更新文档
- 如何在猫鼬中更新文档后添加一些操作
- Mongoose创建一个文档,如果找不到指定的字段,则更新文档中的数组
- Meteor Update集合-未捕获错误:不允许.不受信任的代码只能通过ID更新文档.[403]
- 基于多个下拉列表值更新文档
- 更新文档,但出现错误:对于未定义的值,强制转换为字符串失败
- 如何在 Meteor 中使用多个输入字段和单个更新按钮更新文档
- 弹性搜索更新文档类型
- Meteor:更新文档数组中的嵌套对象
- 在遍历光标和更新文档时,连接因应用程序错误而关闭
- 如何使用Monk在Javascript中的forEach循环中更新文档
- mongoDB-使用$set和一个对象更新文档
- mongodb在给定的时间间隔更新文档
- 使用mongoDB和node.js更新文档时出错
- 更新文档上的Ajax.准备功能
- CouchDB更新文档
- 创建或更新文档时的触发代码
- 仅当文档与数据库不同时更新文档