Search in sources :

Example 1 with Success

use of com.mongodb.reactivestreams.client.Success in project spring-data-mongodb by spring-projects.

the class ReactiveMongoTemplate method insertDBObject.

protected Mono<Object> insertDBObject(final String collectionName, final Document dbDoc, final Class<?> entityClass) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Inserting Document containing fields: " + dbDoc.keySet() + " in collection: " + collectionName);
    }
    final Document document = new Document(dbDoc);
    Flux<Success> execute = execute(collectionName, collection -> {
        MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.INSERT, collectionName, entityClass, dbDoc, null);
        WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction);
        MongoCollection<Document> collectionToUse = prepareCollection(collection, writeConcernToUse);
        return collectionToUse.insertOne(document);
    });
    return Flux.from(execute).last().map(success -> document.get(ID_FIELD));
}
Also used : Document(org.bson.Document) FullDocument(com.mongodb.client.model.changestream.FullDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) Success(com.mongodb.reactivestreams.client.Success)

Aggregations

ReturnDocument (com.mongodb.client.model.ReturnDocument)1 FullDocument (com.mongodb.client.model.changestream.FullDocument)1 Success (com.mongodb.reactivestreams.client.Success)1 Document (org.bson.Document)1