Example usage for org.springframework.data.mongodb.core CollectionOptions empty

List of usage examples for org.springframework.data.mongodb.core CollectionOptions empty

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core CollectionOptions empty.

Prototype

public static CollectionOptions empty() 

Source Link

Document

Create new empty CollectionOptions .

Usage

From source file:example.springdata.mongodb.people.ReactivePersonRepositoryIntegrationTest.java

@Before
public void setUp() {

    operations.collectionExists(Person.class) //
            .flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
            .flatMap(o -> operations.createCollection(Person.class,
                    CollectionOptions.empty().size(1024 * 1024).maxDocuments(100).capped())) //
            .then() //
            .block();//from   w w w. j  a v  a  2s .c o m

    repository.saveAll(Flux.just(new Person("Walter", "White", 50), //
            new Person("Skyler", "White", 45), //
            new Person("Saul", "Goodman", 42), //
            new Person("Jesse", "Pinkman", 27))) //
            .then() //
            .block();

}

From source file:example.springdata.mongodb.people.RxJava2PersonRepositoryIntegrationTest.java

@Before
public void setUp() {

    operations.collectionExists(Person.class) //
            .flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) //
            .flatMap(o -> operations.createCollection(Person.class,
                    CollectionOptions.empty().size(1024 * 1024).maxDocuments(100).capped())) //
            .then() //
            .block();// ww  w  .ja  va 2s.  c om

    repository.saveAll(Flowable.just(new Person("Walter", "White", 50), //
            new Person("Skyler", "White", 45), //
            new Person("Saul", "Goodman", 42), //
            new Person("Jesse", "Pinkman", 27))) //
            .blockingLast();
}

From source file:com.github.danielfernandez.matchday.data.Data.java

public static void initializeAllData(final ReactiveMongoTemplate mongoTemplate) {

    /*/*from   w  w w  . jav  a2 s  .co m*/
     *  Drop collections, then create them again
     */
    final Mono<Void> initializeCollections = mongoTemplate.dropCollection(Team.class)
            .then(mongoTemplate.dropCollection(Match.class)).then(mongoTemplate.dropCollection(Player.class))
            .then(mongoTemplate.dropCollection(MatchEvent.class))
            .then(mongoTemplate.dropCollection(MatchComment.class))
            .then(mongoTemplate.createCollection(Team.class)).then(mongoTemplate.createCollection(Match.class))
            .then(mongoTemplate.createCollection(Player.class))
            .then(mongoTemplate.createCollection(MatchEvent.class,
                    CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
            .then(mongoTemplate.createCollection(MatchComment.class,
                    CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
            .then();

    /*
     * Add some test data to the collections: teams and players will come from the
     * utility Data class, but we will generate matches between teams randomly each
     * time the application starts (for the fun of it)
     */
    final Mono<Void> initializeData = mongoTemplate
            // Insert all the teams into the corresponding collection and log
            .insert(Data.TEAMS, Team.class).log(LOGGER_INITIALIZE, Level.FINEST)
            // Collect all inserted team codes and randomly shuffle the list
            .map(Team::getCode).collectList().doOnNext(Collections::shuffle)
            .flatMapMany(list -> Flux.fromIterable(list))
            // Create groups of two teams and insert a new Match for them
            .buffer(2).map(twoTeams -> new Match(twoTeams.get(0), twoTeams.get(1)))
            .flatMap(mongoTemplate::insert).log(LOGGER_INITIALIZE, Level.FINEST)
            .concatMap(match -> mongoTemplate
                    .insert(new MatchEvent(match.getId(), MatchEvent.Type.MATCH_START, null, null)))
            // Finally insert the players into their corresponding collection
            .thenMany(Flux.fromIterable(Data.PLAYERS)).flatMap(mongoTemplate::insert)
            .log(LOGGER_INITIALIZE, Level.FINEST).then();

    /*
     * Perform the initialization, blocking (that's OK, we are bootstrapping a testing app)
     */
    initializeCollections.then(initializeData).block();

}

From source file:org.mongodb.redis.integration.WebFluxIntegrationTests.java

@BeforeAll
void setUp() throws Exception {
    if (!this.operations.collectionExists(Book.class).block()) {
        this.operations.createCollection(Book.class,
                CollectionOptions.empty().size(1024 * 1024).maxDocuments(100).capped()).then().block();
    }/* w  w  w.j a va 2 s.  c  om*/
    this.bookRepository.save(Book.builder().title("MongoDbCookBook").text("MongoDB Data Book").author("Raja")
            .bookId("1").build()).then().block();
}