Java MongoDB bulk insert from stream

245 Views Asked by At

I'm trying to insert a few million documents into MongoDB in one operation. Using MongoCollection.insertMany does not work for me because it takes a List as input and my data does not fit in memory.

Is it possible to insert documents from a stream instead?

1

There are 1 best solutions below

0
Tom Elias On BEST ANSWER

you need to use Bulk Insert operations from your stream. please read: Bulk Insert

try to execute() the bulk after a reasonable number of documents (inside your consumer lambda) because after all there is a limit to the size of the request Mongo can handle.