Home > database >  Java MongoDB bulk insert from stream
Java MongoDB bulk insert from stream

Time:12-19

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?

CodePudding user response:

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.

  • Related