Java Code Examples for org.springframework.data.mongodb.core.ReactiveMongoOperations

The following examples show how to use org.springframework.data.mongodb.core.ReactiveMongoOperations. These examples are extracted from open source projects. 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
/**
 * 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
public MongodbProcessorConfiguration(
	MongodbProcessorProperties properties,
	ReactiveMongoOperations mongoTemplate,
	BeanFactory beanFactory
) {
	this.properties = properties;
	this.mongoTemplate = mongoTemplate;
	this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(beanFactory);
}
 
Example 3
/**
 * Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}.
 *
 * @param method must not be {@literal null}.
 * @param projectionFactory - the projection factory
 */
@Autowired
public ReactiveAggregateMongoQuery(Method method, RepositoryMetadata metadata, ReactiveMongoOperations mongoOperations,
                                   ProjectionFactory projectionFactory, MongoQueryExecutor queryExecutor) {
  super(new ReactiveMongoQueryMethod(method, metadata, projectionFactory,
                                     mongoOperations.getConverter().getMappingContext()),
        mongoOperations,
        new SpelExpressionParser(),
        CONTEXT_PROVIDER);
  this.mongoOperations = mongoOperations;
  this.method = method;
  this.queryExecutor = queryExecutor;
}
 
Example 4
/**
 * Creates a new {@link MongoRepositoryFactory} with the given {@link MongoOperations}.
 *
 * @param mongoOperations must not be {@literal null}
 * @param queryExecutor - the query executor
 */
public ReactiveAggregateQuerySupportingRepositoryFactory(ReactiveMongoOperations mongoOperations,
                                                         MongoQueryExecutor queryExecutor) {
  super(mongoOperations);
  this.mongoOperations = mongoOperations;
  this.queryExecutor = queryExecutor;
}
 
Example 5
Source Project: tutorials   Source File: WarnLogsCounter.java    License: MIT License 5 votes vote down vote up
public WarnLogsCounter(ReactiveMongoOperations template) {
    Flux<Log> stream = template.tail(query(where(LEVEL_FIELD_NAME).is(LogLevel.WARN)), Log.class);
    subscription = stream.subscribe(logEntity -> {
      log.warn("WARN log received: " + logEntity);
      counter.incrementAndGet();
    });
}
 
Example 6
@Autowired
DefaultUserRepository(ReactiveMongoOperations mongoOperations) {
    this.mongoOperations = mongoOperations;
}
 
Example 7
public DataInitializer(ReactiveMongoOperations mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
}
 
Example 8
public ReactiveMongoNativeJavaDriverQueryExecutor(ReactiveMongoOperations mongoOperations) {
  super(mongoOperations);
  initialize(mongoOperations);
}
 
Example 9
public ReactiveMongoNativeJavaDriverQueryExecutor(ReactiveMongoOperations mongoOperations, ObjectMapper objectMapper) {
  super(mongoOperations, objectMapper);
  initialize(mongoOperations);
}
 
Example 10
private void initialize(ReactiveMongoOperations mongoOperations) {
  Document result = mongoOperations.executeCommand("{buildinfo:1}").block();
  this.isMongo360OrLater = ((String)result.get("version")).startsWith(MONGO_V3_6_VERSION);
}
 
Example 11
@Override
protected RepositoryFactorySupport getFactoryInstance(ReactiveMongoOperations operations) {
  Assert.notNull(queryExecutor, "Query executor cannot be null");
  return new ReactiveAggregateQuerySupportingRepositoryFactory(operations, queryExecutor);
}
 
Example 12
@Bean
public ReactiveMongoOperations reactiveMongoOperations(MongoClient mongoClient, String dbName) {
  return new ReactiveMongoTemplate(mongoClient, dbName);
}
 
Example 13
@Bean
public MongoQueryExecutor queryExecutor(ReactiveMongoOperations mongoOperations) {
  return new ReactiveMongoNativeJavaDriverQueryExecutor(mongoOperations);
}
 
Example 14
private Mono<Process> finish(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.DONE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}
 
Example 15
Mono<Process> start(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.ACTIVE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}
 
Example 16
private Mono<Process> finish(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.DONE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}
 
Example 17
Mono<Process> start(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.ACTIVE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}