MONGO_OBJECT_REMOVED ERROR when trying to Insert Data into Mongo Collection

261 views Asked by At

When I was trying to insert the data into the MongoDB, the console.log of rcitems gave me an "MONGO_OBJECT_REMOVED" error.

Currently using Meteor, Blaze, Simpl-Schema, and Collection2

The rcitems suppose to show an array of product, quantity, lot , and expire date Object.

When I removed the INSERT to Mongo Code, the rcitems display the data correctly.

Please see the image for your reference.

ERROR Image

Working image after remove 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

There are 1 answers

0
CHiEZ On

I have figure out the solution.

blackbox does not work with type: Array so I changed from

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

to

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