Java Code Examples for org.springframework.data.mongodb.core.MongoOperations#createCollection()

The following examples show how to use org.springframework.data.mongodb.core.MongoOperations#createCollection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebfluxDemo.java    From spring-five-functional-reactive with Apache License 2.0 6 votes vote down vote up
/**
 * Application runner to initialize a capped collection for {@link Event}s and insert a new {@link Event} every two
 * seconds.
 * 
 * @param operations
 * @param reactiveOperations
 * @return
 */
@Bean
ApplicationRunner onStart(MongoOperations operations, ReactiveMongoOperations reactiveOperations) {

	return args -> {

		CollectionOptions options = CollectionOptions.empty() //
				.capped() //
				.size(2048) //
				.maxDocuments(1000);

		operations.dropCollection(Event.class);
		operations.createCollection(Event.class, options);

		Flux.interval(Duration.ofSeconds(2)) //
				.map(counter -> new Event(LocalDateTime.now())) //
				.flatMap(reactiveOperations::save) //
				.log() //
				.subscribe();
	};
}
 
Example 2
Source File: MongoConfig.java    From service-block-samples with Apache License 2.0 5 votes vote down vote up
@Bean
CommandLineRunner commandLineRunner(MongoOperations operations) {
    return (args) -> {
        // Setup the streaming data endpoint
        if (operations.collectionExists("tightCouplingEvent")) {
            operations.dropCollection("tightCouplingEvent");
        }
        if (operations.collectionExists("query")) {
            operations.dropCollection("query");
        }

        CollectionOptions options = new CollectionOptions(5242880, 100000, true);
        operations.createCollection("tightCouplingEvent", options);
    };
}