Is it possible to make insertmany return the inserted documents?

I’ve just upgraded my mongodb driver from an older version and I noticed that insertmany doesn’t return the inserted documents aymore.

Using find right after an insert to return the created documents seems odd, is this the way to go now or is it possible to have insertmany return the created docs ?

at least no such feature from manual.

But you are inserting the documents by calling API, so you are supposed to know what are being inserted. InsertMany can return a lot of info to you, including any failures.

1 Like

Hi @coffee_cup, Looking at the node.js tag, I assume you are talking about node driver.
Please see the InsertManyResult | mongodb which should give you IDs of inserted documents, which is returned by insertMany (Collection | mongodb)

1 Like

yea I noticed that, however the driver version I used before returned all inserted documents ( not only the ID ), but looks like thats the way to go now.

Thanks anyways.

1 Like