Collection insert failing silently

I have some code running inside of Meteor.startup function that does the following:

Collection.remove({ status: 'Imported' });
/* Some processing here to create an object */
console.dir(myObject, { depth: 5 });

The server console has NO errors and only displays the objects that are to be inserted. The insert just seems to be failing silently and I have yet to figure out a way to debug what might be happening. The colleciton is using the current simpleSchema npm package and I have enabled debugging there to see if anything being generated. This is silent as well.

I can copy the object being dumped and go into meteor mongo and insert it just fine into the database so it appears to be correct though I realize this is not the greatest of tests.

Suggestions on how to determine what might be happening?

You can maybe add a callback to the insert function and output the err to have more details about what happen ?

See : Mongo.Collection#insert(doc, [callback])

1 Like

Yes, sorry I forgot to mention that I have already tried that as well. crated a callback:

(error, result) => {
  console.log('Insert callback');

callback is never triggering! Thanks for the suggestion though, appreciate it.

What is the return value of your insert? Usually it returns the _id of the document. What other packages are you using? Anything that deals with collections?

I use the aldeed:meteor-collection2 package (which uses simpleSchema), and I have seen that inserts and updates can fail silently at the schema when you add a callback to the insert/update on the server.

I don’t know why exactly , I think it has to do with the package doing all of the error handling. Once i tried making the call from the client and having the callback only on the client, the schema error came back, and was also logged on the server (without me calling a console.log).

I would try to take it out of startup and put it in a method that you call on the client, and see what the callback says.

I don’t have time too investigate it deeply now, but I hope this helps?


collection2 does sanity checks based on the Schema and can reject inserts. I once had a similar problem. There is a collection2 specific option you can pass to insert to forego those checks

1 Like

I am using collection2 so I will definitely look into this. Thanks!

I looked it up in my code and here is a link to the docs. Try inserting without validating

myCollection.insert(doc, {validate: false});