Monogdb更新功能在终端上起作用,但在Metoer服务器上不起作用

时间:2018-06-20 10:09:56

标签: mongodb meteor

我想弄清楚我在做什么错,但绝对没有运气。

db.attendances.update({ _id: 'hRs6LfAqPBmy4ZNuH' }, { $set: { absentParentOrGuardianDate: undefined } })

如果我使用' meteor mongo 'absentParentOrGuardianDate在终端外壳中运行此更新命令,但是Attendances.update({ _id: 'hRs6LfAqPBmy4ZNuH' }, { $set: { absentParentOrGuardianDate: undefined } });已从文档中删除,但是,如果我运行相同的代码,则对流星略有更改,在流星服务器上,我得到一个错误。

{isClientSafe: true, error: 500, reason: "Internal server error", details: undefined, message: "Internal server error [500]", …}

错误是: private void RunPythonActionPerformed(java.awt.event.ActionEvent evt) { String pythonScriptPath = "path to python file"; String[] cmd = new String[2]; cmd[0] = "python"; // check version of installed python: python -V cmd[1] = pythonScriptPath; // create runtime to execute external command Runtime rt = Runtime.getRuntime(); Process pr = null; try { pr = rt.exec(cmd); // retrieve output from python script } catch (IOException ex) { Logger.getLogger(Page2.class.getName()).log(Level.SEVERE, null, ex); } BufferedReader bfr = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line = ""; try { while((line = bfr.readLine()) != null) { // display each output line form python script System.out.println(line); } // TODO add your handling code here: } catch (IOException ex) { Logger.getLogger(Page2.class.getName()).log(Level.SEVERE, null, ex); } }

有人可以告诉我我在这里想念的东西吗?

1 个答案:

答案 0 :(得分:0)

import { _ } from 'meteor/underscore';

const updateDoc = {};
_.each(yourObj, (value, key) => { // I'm using underscore to help loop through the object
  if (value) {
    updateDoc.$set[key] = value;
  } else {
    updateDoc.$unset[key] = value;
  }
});
yourCollection.update(yourSelector, updateDoc);