14

I am trying out reactive support in spring-data with MongoDB. I am using spring-boot 2.0.0.

Generally I would write a domain object like this in my project:

@Document
public class PriceData {
    ......
}

With this spring-data it would create a collection with name priceData in MongoDB. If I want to customize it, then I would do it using the collection attribute:

@Document(collection = "MyPriceData")

Since I want to try reactive support of MongoDB, I want to create a capped collection so that I can use @Tailable cursor queries.

I can create a capped collection in my MongoDB database as specified here:

CollectionOptions options = new CollectionOptions(null, 50, true);
mongoOperations.createCollection("myCollection", options);

or

db.runCommand({ convertToCapped: 'MyPriceData', size: 9128 })

This is not a big problem if I use some external MongoDB database where I can just run this command once. But if I use an embedded MongoDB, then I would have put this in a class which would be executed every time during start up.

Either way I would be creating a collection even before the first request. So I was wondering if there is a way, I could specify to spring-data-mongodb that I need a capped collection instead of regular collection. Unfortunately @Document doesn't help in this case.

pvpkiran
  • 25,582
  • 8
  • 87
  • 134
  • Creating a capped collection using document annotation is not supported unless you are expecting an answer providing a support for capped option for document annotation. Can you show how are you using embedded mongo ? Is it through de.flapdoodle.embed dependency with spring boot ? Just wanted to understand what is your expectation. – s7vr Feb 08 '18 at 18:00
  • @Veeram I am using embedded mongo through flapdoodle dependency. My expectation is, may be in future versions of spring-data-mongodb, there is an option in `@Document` to specify something like `capped=true` – pvpkiran Feb 09 '18 at 08:36

1 Answers1

4

So below is from Oliver

Might be a good idea to have those options exposed to the @Document annotation to automatically take care of them when building the mapping context but we generally got the feedback of people wanting to manually handle those collection setup and indexing operations without too much automagic behavior. Feel free to open a JIRA in case you'd like to see that supported nevertheless.

This is back in 2011. And it seems its still true to date. If you really need the change to handle it using annotation, you should open a JIRA ticket

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265