0

I have written an application that uses Spring MongoRepository to connect to a collection of Product Sales, which contains sales data for all products.

NOw, I am facing a problem, since instead of one single collection, I have now several collections of Product Sales, each containing one single product. All collections structure is still the same, but now each collection name is something like 'Sales_123', 'Sales_456', where the numeric suffix is the product Id.

It means I can no longer use the Document annotation to specify the collection name. Can I still do something to pass the collection name at runtime to MongoRepository?

Perhaps, is there any feasible way to plug a modified MappingMongoEntityInformation to which I could pass some way the collection name?

Or is it better to just re-write the whole thing using mongoTemplate?

  • Maybe here is a answer for your question http://mongorepository.codeplex.com/discussions/456452. But if you need more flexibility to work with repository and collection configuration, you can use mongoTemplate. http://stackoverflow.com/a/17010650/3568708 – jmen7070 May 06 '14 at 10:05
  • Thanks, the links were very useful. I have solved my problem by using the Spring mongo operations that allow the collection to be specified (the first link you gave me for mongodb shows those methods, so found them exposed in spring mongo too). – user3607521 May 07 '14 at 10:00
  • I added my repository impl class, but did not allow Spring to automatically implement anything for that repo since it would not have been correct, as the implementation that Spring would have added would not know the correct collection name – user3607521 May 07 '14 at 10:02

1 Answers1

0

Posting an answer resurrects this old discussion, but I have answered this in another discussion that I resurrected. I am also posting a link to my answer here just in case someone finds this old thread. Have a look at https://stackoverflow.com/a/65036567/8031498 where I describe how to use spel to specify the collection name.

Steve Storck
  • 793
  • 6
  • 25