title: Creating a capped collection using Spring data MongoDB @Document
body: <p>I am trying out reactive support in spring-data with MongoDB. I am using spring-boot 2.0.0.</p>
  
  <p>Generally I would write a domain object like this in my project:</p>
  
  <pre><code>@Document
  public class PriceData {
      ......
  }
  </code></pre>
  
  <p>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 <code>collection</code> attribute:</p>
  
  <pre><code>@Document(collection = "MyPriceData")
  </code></pre>
  
  <p>Since I want to try reactive support of MongoDB, I want to create a capped collection so that I can use <code>@Tailable</code> cursor queries.</p>
  
  <p>I can create a capped collection in my MongoDB database as specified <a href="https://stackoverflow.com/questions/7904526/how-to-create-a-capped-collection-with-spring-data-mongodb">here</a>:</p>
  
  <pre><code>CollectionOptions options = new CollectionOptions(null, 50, true);
  mongoOperations.createCollection("myCollection", options);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>db.runCommand({ convertToCapped: 'MyPriceData', size: 9128 })
  </code></pre>
  
  <p>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.</p>
  
  <p>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 <code>@Document</code> doesn't help in this case.</p>