尝试将数据插入Mongo Collection时MONGO_OBJECT_REMOVED错误

时间:2017-09-14 09:34:18

标签: javascript mongodb meteor meteor-collection2

当我尝试将数据插入MongoDB时, rcitems 的console.log给了我“MONGO_OBJECT_REMOVED”错误。

目前正在使用Meteor,Blaze,Simpl-Schema和Collection2

rcitems假设显示产品,数量,批次和过期日期对象的数组。

当我删除I​​NSERT到Mongo代码时,rcitems正确显示数据。

请参阅图片以供参考。

ERROR Image

删除Receive.insert(...)

后的工作图像

Working Image

Template.receiveForm.events({
  'submit form': function(event, template){
    event.preventDefault();
    var rcitems = [];
    let docdate = event.target.docdate.value;
    docdate = moment(docdate, "DD-MM-YYYY").toISOString();
    let supplier = event.target.supplier_sel.value;
    var trs = $('tbody tr');

    //Build receiveLot Array
    trs.each(function(tr){
      let prodid = $(this).closest('tr').attr('id');
      let prodname = $(this).find(".prodname").html();
      let quantity = Number($(this).find("#quantity").val());
      let lot = $(this).find("#lotno").val() || 0;
      let expdate = $(this).find("#expdate").val() || 0;
      console.log(prodid);
      console.log(prodname);
      console.log(quantity)
      console.log(lot)
    });
    console.log(rcitems);
    var recvdoc = {'docdate' : docdate, 'supplier': supplier, 'receiveItems': rcitems};
    console.log(recvdoc);
    //Insert to Receive Collection
    Receive.insert(recvdoc, function( error, result ){
      if (error) {
        console.log(error);
      } else {
        console.log("Insert Success");
        console.log(result);
      }
    });
  }
});

SCHEMA

import SimpleSchema  from 'simpl-schema';

Receive = new Mongo.Collection("receive");
Receive.attachSchema(new SimpleSchema({
  docdate: {
    type: Date,
    label: "Document Date",
  },
  supplier: {
    type: String,
    label: "Supplier",
  },
  receiveItems:{
    type: Array,
    blackbox: true,
    label: "Receive Lot",
  },
}));

1 个答案:

答案 0 :(得分:0)

我已经找到了解决方案。

blackbox 不适用于类型:数组所以我改为

  receiveItems:{
    type: Array,
    blackbox: true,
    label: "Receive Lot",
  },

  receiveItems:{
    type: Array,
    label: "Receive Lot",
  },
  'receiveItems.$':{
    type: Object,
    blackbox: true,
  },