MongoDB: Handle errors from Bulk.insert() method

1k Views Asked by At

I'm using that method, but I do not know how to handle the result. I've checked that Bulk.insert() returns a promise, but I do not have much experience with that topic. This is my code:

bulk.insert({
        id_cliente: val1,
        iddoi: val2,
        id_personeria: val3,
        cliente: val4
});

bulk.execute()

I have no problems with data insertion, but I want to get the answer, because there are duplicate records and I need to know what they are.

1

There are 1 best solutions below

1
On

you can use the BulkWriteResult object returned from the execute() call.

https://docs.mongodb.com/manual/reference/method/BulkWriteResult/#BulkWriteResult

if you need more details, you can call getOperations()