By default save() is used to add a document into the collection (defined in Model class). How to insert a document or Query to insert a document into the specific collection using Spring Data? Something like save(document,CollectionName).
The MongoOperations and MongoTemplate classes have an option in the save method to pass the collection name.
The class org.springframework.data.repository.CrudRepository is present in the core library which is not specific to Mongo. So, it doesn't have an option to pass the Mongo collection name.
MongoOperations save with collection name
MongoTemplate save with collection name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With