While attempting to insert data into MongoDB, the console.log output for rcitems showed an error message indicating "MONGO_OBJECT_REMOVED".
I am currently utilizing Meteor, Blaze, Simple-Schema, and Collection2.
The expected outcome for rcitems is to display an array of product, quantity, lot, and expiration date Objects.
Upon removing the INSERT to Mongo Code, the rcitems displayed the data correctly.
Please refer to the following image for details: ERROR Image
The image shows correct functionality after removing the Receive.insert(...) code: 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",
},
}));