Search in sources :

Example 11 with FindOneAndReplaceOptions

use of com.mongodb.client.model.FindOneAndReplaceOptions in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method findAndReplaceShouldUseDefaultCollationWhenPresent.

// DATAMONGO-1854
@Test
void findAndReplaceShouldUseDefaultCollationWhenPresent() {
    template.findAndReplace(new BasicQuery("{}"), new Sith());
    ArgumentCaptor<FindOneAndReplaceOptions> options = ArgumentCaptor.forClass(FindOneAndReplaceOptions.class);
    verify(collection).findOneAndReplace(any(), any(), options.capture());
    assertThat(options.getValue().getCollation().getLocale()).isEqualTo("de_AT");
}
Also used : FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Test(org.junit.jupiter.api.Test)

Example 12 with FindOneAndReplaceOptions

use of com.mongodb.client.model.FindOneAndReplaceOptions in project engine by Lumeer.

the class MongoViewDao method updateView.

@Override
public View updateView(final String id, final View view) {
    JsonView jsonView = new JsonView(view);
    FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER);
    try {
        View updatedView = databaseCollection().findOneAndReplace(idFilter(id), jsonView, options);
        if (updatedView == null) {
            throw new StorageException("View '" + view.getId() + "' has not been updated.");
        }
        return updatedView;
    } catch (MongoException ex) {
        throw new StorageException("Cannot update view: " + view, ex);
    }
}
Also used : FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) MongoException(com.mongodb.MongoException) JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) StorageException(io.lumeer.storage.api.exception.StorageException)

Example 13 with FindOneAndReplaceOptions

use of com.mongodb.client.model.FindOneAndReplaceOptions in project engine by Lumeer.

the class MongoDataDao method updateData.

@Override
public DataDocument updateData(final String collectionId, final String documentId, final DataDocument data) {
    Document document = new Document(data);
    FindOneAndReplaceOptions options = new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER);
    Document updatedDocument = dataCollection(collectionId).findOneAndReplace(idFilter(documentId), document, options);
    if (updatedDocument == null) {
        throw new StorageException("Document '" + documentId + "' has not been updated (replaced).");
    }
    return MongoUtils.convertDocument(updatedDocument);
}
Also used : FindOneAndReplaceOptions(com.mongodb.client.model.FindOneAndReplaceOptions) Document(org.bson.Document) DataDocument(io.lumeer.engine.api.data.DataDocument) ReturnDocument(com.mongodb.client.model.ReturnDocument) StorageException(io.lumeer.storage.api.exception.StorageException)

Aggregations

FindOneAndReplaceOptions (com.mongodb.client.model.FindOneAndReplaceOptions)13 Document (org.bson.Document)5 ReturnDocument (com.mongodb.client.model.ReturnDocument)4 Test (org.junit.jupiter.api.Test)4 BsonDocument (org.bson.BsonDocument)3 ObjectId (org.bson.types.ObjectId)3 Test (org.junit.Test)3 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)3 StorageException (io.lumeer.storage.api.exception.StorageException)2 Bson (org.bson.conversions.Bson)2 MongoException (com.mongodb.MongoException)1 Worker (com.mongodb.client.test.Worker)1 WorkerCodecProvider (com.mongodb.client.test.WorkerCodecProvider)1 JsonView (io.lumeer.api.dto.JsonView)1 View (io.lumeer.api.model.View)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 Date (java.util.Date)1 Map (java.util.Map)1 BsonString (org.bson.BsonString)1 BsonValue (org.bson.BsonValue)1