Meteor mongo insert hangs

Hello there,

I’m having trouble while inserting ~2MB document into my collection in meteor. Actually it stuck during insert and neither throwing an error or returning a result.

Here’s the source of how I’m creating this collection.

And here’s a code snippet which I’m using for insert:

Connections.insert(document, function (err, res) {
                    console.log(err);
                    console.log(res);
});

Note that, document is an object and it has a simple array (such as [{"key":1,"key2":2}]) which approx. has size 100.000 if it matters.

Thanks in advance

MongoDB has some hard limits for how big your documents and collections can be. Please refer to the manual and see if that can be your problem.

Also, I see you use schemas for your collection. Its possible that it gets stuck on validating your document against the schema because it’s so big. If that’s the case, you can bypass the validation by calling:

Connections._collection.insert(...);

This will call the MongoDB driver directly bypassing collection2 mechanisms for cleaning and validating your document.

1 Like

I know most of the limitations of mongodb. But that’s not the case since my document is about 2 MB and mongodb has 16MB limitation.

Apart from that, your code worked like a charm. You’re right its all about validation of schema in my case.

Thank you so much.

Glad it helped :slight_smile:. Keep in mind though that you’re essentially throwing most of the benefits of having a schema if you do inserts that way, so use this only if it’s absolutely neccesary.