MongoDB Multiple insert at once

We can insert multiple documents (bulk insert) to a collection using a single insert command :


Syntax :
   db.[COLLECTION].insert( [ { DOC1 }, {DOC2} ] ) ;

Example :
   db.people.insert( [ {name: "Ganesh", age: 24, country : "Nepal"}, {name: "John", age : 20} ]);

In Java  ( Using Spring Data JPA Repository )

   personRepository.insert( personList);
   --> It follows org.springframework.data.mongodb.repository.MongoRepository#insert(Iterable<S> entities) method's syntax

No comments :

Post a Comment

Your Comment and Question will help to make this blog better...