Creating a mongodb capped collection in java

后端 未结 2 1621
鱼传尺愫
鱼传尺愫 2021-02-10 22:58

I want to create a capped collection from Java code. I found the syntax for creating it through JavaScript, but could not find an example for Java.

Mongo mongo =         


        
2条回答
  •  眼角桃花
    2021-02-10 23:44

    With more recent java mongo driver (ie 3.4) the creation should slightly change:

    CreateCollectionOptions opts = new CreateCollectionOptions().capped(true).sizeInBytes(1024*1024);
    database.createCollection("test", opts);
    

    Please, notice that the createCollection is not returning any value.

提交回复
热议问题