0

I am fetching data from api and storing it in database ,I have to delete the whole document and refresh data from api and store it again ,on live server doing this will cause delay for users to get back the data again. Is there any possibility to change the

@Document(collection = "events")
@JsonIgnoreProperties(ignoreUnknown=true)

collection name at runtime ?? .I have gone through following link -Changing Table name dynamiclly in JPA/Hibernate for JPA but that doesnt solve my query any help would be really appreciated.

  • To paraphrase you want to insert the data you retrieve from the API into different collections based on some conditional using spring-data-mongodb? Is that correct? – Trevor Gowing Oct 30 '18 at 15:53
  • yes and when one collection is deleted suppose i put a cron job a 3pm everyday so at that time second updated collection will be used –  Oct 30 '18 at 16:16

1 Answers1

0

Instead of specifying the collection name in the Document annotation I would suggest using MongoTemplate#insert(Object document, String collectionName) similarly to this example from the Spring Data MongoDB Documentation.

This way you could specific collection name at runtime using a property or environment variable.

Trevor Gowing
  • 2,236
  • 22
  • 25