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.
Working image after remove Receive.insert(...)
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",
},
}));
I have figure out the solution.
blackbox does not work with type: Array so I changed from
to