meteor不会更新mongodb中的数据 [英] meteor wont update data in mongodb

查看:108
本文介绍了meteor不会更新mongodb中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

Nodes = new Meteor.Collection("nodes");
[...]
Template.list.events({
  'click .toggle': function () {
      Session.set("selected_machine", this._id);
      Nodes.update(Session.get("selected_machine"), {$set: {"conf" :{"flag": true }}});
  }
});

我无法说服meteor更新我的参赛作品。 DOM中的微秒闪存
,但是服务器拒绝更新。

I can't convince meteor to update my entry. Theres a microsecond flash in the DOM, but the server rejects to update.

这是我的数据:
{_ id:ObjectId( 50d8ec4f5919ffef343c9151),conf:{flag:false},name:sepp}

This is my data: { "_id" : ObjectId("50d8ec4f5919ffef343c9151"), "conf" : { "flag" : false }, "name" : "sepp" }

console.log(Session.get(selected_machine ));告诉我身份证。安装了不安全的软件包。在minimongo控制台中手动编写按预期工作。

console.log(Session.get("selected_machine")); shows me the id. Insecure Package is installed. Writing by hand in the minimongo console works as expected.

是否存在问题,因为我不想更新子阵列?
我做错了什么?谢谢你的帮助

Is there a Problem because I wan't to update a subarray? What am I doing wrong? Thank you for help

推荐答案

这是因为你的数据使用的是MongoDB ObjectId,这是Meteor无法更新这些问题的已知问题值( https://github.com/meteor/meteor/issues/61 )。

This is because your data uses the MongoDB ObjectId, it's a known issue that Meteor can't update these values (https://github.com/meteor/meteor/issues/61).

你可以在mongo shell(meteor mongo)中运行这个hack来修复它(归功于 antoviaque ,我刚刚为你的收藏编辑了它)

you could run this hack in the mongo shell (meteor mongo) to fix it (credit to antoviaque, i just edited it for your collection)

db.nodes.find({}).forEach(function(el){
    db.nodes.remove({_id:el._id}); 
    el._id = el._id.toString(); 
    db.nodes.insert(el); 
});

Meteor将ObjectId视为字符串,因为MongoDB没有找到要更新的内容。
它在客户端工作,因为在你的本地集合中,这些_id被转换为字符串。

Meteor sees the ObjectId just as a string and because of that MongoDB doesn't find something to update. It works client-side, because in your local collection these _id's are converted to strings.

对于实验,你应该通过浏览器控制台插入数据,而不是通过mongo shell,因为那时Meteor会为你生成UUID,一切都会(并且会很好)。

For experimenting you should insert data via the browser console and not via the mongo shell, because then Meteor generates UUID's for you and everything is (and will be) fine.

PS:当我开始使用我的App时,我遇到了同样的问题。

PS: I ran into the same problem when I started on my App.

这篇关于meteor不会更新mongodb中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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