mikowals/batch-insert

Error handling

Closed this issue · 3 comments

When using the callback version, what is inside the error object? I seem to be getting always an array of objects, so is it always failing? However my DB doesn seem to chage.

I am also checking if the return value length matches the length of the array I am inserting, but it never seems to match either.

Maybe I am doing something wrong?

Based on your report I think I found a mistake in how batchInsert with a callback works on the server. Specifically any error on the server will always throw and not be passed to the callback. If there is no error the the callback is called with only one argument - the result.

So based on your description, I think your db probably is being updated and the first argument of the callback is an array of added _ids. I can investigate more if you share a reproduction.

I will fix the callback handling on the server in a release soon.

Thank you for looking into this. We still see an error, specifically "No or incomplete number of IDs returned." is printed when running this:

count = docsToInsert.length;
try {
    newIds = collection.batchInsert(docsToInsert, function (err, res) {

        if (err) {
            console.log('Batch insertion problem...');
        } else {

        }

        docsToInsert.length = 0;
    });
} catch (e) {
    console.log('Failed to insert...');
}
if (!newIds || newIds.length != count) {
    console.log('No or incomplete number of IDs returned.');
}

I published up a new version last week that works with meteor-1.2-rc.17 that fixed the error I found. I actually made the changes back in early August but did them based on the Meteor dev branch and have been waiting patiently to publish with the new release.

Now that 1.2 is out I will publish an updated version for it on the weekend. Thanks for the reports.