use of com.mongodb.reactivestreams.client.MongoDatabase in project micronaut-data by micronaut-projects.
the class DefaultReactiveMongoRepositoryOperations method findOne.
@Override
public <T> Mono<T> findOne(Class<T> type, Serializable id) {
return withClientSession(clientSession -> {
RuntimePersistentEntity<T> persistentEntity = runtimeEntityRegistry.getEntity(type);
MongoDatabase database = getDatabase(persistentEntity, null);
MongoCollection<T> collection = getCollection(database, persistentEntity, type);
Bson filter = MongoUtils.filterById(conversionService, persistentEntity, id, collection.getCodecRegistry());
if (QUERY_LOG.isDebugEnabled()) {
QUERY_LOG.debug("Executing Mongo 'find' with filter: {}", filter.toBsonDocument().toJson());
}
return Mono.from(collection.find(clientSession, filter, type).first());
});
}
use of com.mongodb.reactivestreams.client.MongoDatabase in project micronaut-data by micronaut-projects.
the class DefaultReactiveMongoRepositoryOperations method persistManyAssociation.
@Override
public Mono<Void> persistManyAssociation(MongoOperationContext ctx, RuntimeAssociation runtimeAssociation, Object value, RuntimePersistentEntity<Object> persistentEntity, Object child, RuntimePersistentEntity<Object> childPersistentEntity) {
String joinCollectionName = runtimeAssociation.getOwner().getNamingStrategy().mappedName(runtimeAssociation);
MongoDatabase mongoDatabase = getDatabase(persistentEntity, ctx.repositoryType);
MongoCollection<BsonDocument> collection = mongoDatabase.getCollection(joinCollectionName, BsonDocument.class);
BsonDocument association = association(collection.getCodecRegistry(), value, persistentEntity, child, childPersistentEntity);
if (QUERY_LOG.isDebugEnabled()) {
QUERY_LOG.debug("Executing Mongo 'insertOne' for collection: {} with document: {}", collection.getNamespace().getFullName(), association);
}
return Mono.from(collection.insertOne(ctx.clientSession, association)).then();
}
use of com.mongodb.reactivestreams.client.MongoDatabase in project pinpoint by naver.
the class MongoReactivePluginController method insertOn.
@GetMapping(value = "/mongodb/insertOne")
public String insertOn() throws Throwable {
MongoDatabase db = getDatabase();
MongoCollection<Document> collection = db.getCollection("test");
Document canvas = new Document("item", "canvas").append("qty", 100).append("tags", Collections.singletonList("cotton"));
Document size = new Document("h", 28).append("w", 35.5).append("uom", "cm");
canvas.put("size", size);
ObservableSubscriber<InsertOneResult> sub = new ObservableSubscriber<>();
collection.insertOne(canvas).subscribe(sub);
sub.waitForThenCancel(1);
return "Insert=" + sub.getResults();
}
Aggregations