Search in sources :

Example 31 with DeleteResult

use of com.mongodb.client.result.DeleteResult in project jnosql-diana-driver by eclipse.

the class MongoDBDocumentCollectionManager method delete.

@Override
public void delete(DocumentDeleteQuery query) {
    String collectionName = query.getDocumentCollection();
    MongoCollection<Document> collection = mongoDatabase.getCollection(collectionName);
    Bson mongoDBQuery = DocumentQueryConversor.convert(query.getCondition().orElseThrow(() -> new IllegalArgumentException("condition is required")));
    DeleteResult deleteResult = collection.deleteMany(mongoDBQuery);
}
Also used : Document(org.bson.Document) MongoDBUtils.getDocument(org.jnosql.diana.mongodb.document.MongoDBUtils.getDocument) BsonDocument(org.bson.BsonDocument) DeleteResult(com.mongodb.client.result.DeleteResult) Bson(org.bson.conversions.Bson)

Example 32 with DeleteResult

use of com.mongodb.client.result.DeleteResult in project presto by prestodb.

the class MongoSession method deleteTableMetadata.

private boolean deleteTableMetadata(SchemaTableName schemaTableName) {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    MongoDatabase db = client.getDatabase(schemaName);
    if (!collectionExists(db, tableName)) {
        return false;
    }
    DeleteResult result = db.getCollection(schemaCollection).deleteOne(new Document(TABLE_NAME_KEY, tableName));
    return result.getDeletedCount() == 1;
}
Also used : Document(org.bson.Document) DeleteResult(com.mongodb.client.result.DeleteResult) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 33 with DeleteResult

use of com.mongodb.client.result.DeleteResult in project pinpoint by naver.

the class MongoDBITBase method deleteData.

public void deleteData(PluginTestVerifier verifier, MongoCollection<Document> collection, Class<?> mongoDatabaseImpl) {
    // delete data
    Document doc = new Document("name", "Roy3");
    DeleteResult deleteResult = collection.deleteMany(doc);
    Method deleteMany = getMethod(mongoDatabaseImpl, "deleteMany", Bson.class);
    NormalizedBson parsedBson = parseBson(doc);
    verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, deleteMany, null, MongoDBITConstants.MONGODB_ADDRESS, null, new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers"), new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "MAJORITY"), new ExpectedAnnotation(MongoConstants.MONGO_JSON_DATA.getName(), new StringStringValue(parsedBson.getNormalizedBson(), parsedBson.getParameter()))));
    Assert.assertEquals(1, deleteResult.getDeletedCount());
}
Also used : ExpectedAnnotation(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation) StringStringValue(com.navercorp.pinpoint.common.util.StringStringValue) NormalizedBson(com.navercorp.pinpoint.plugin.mongo.NormalizedBson) Method(java.lang.reflect.Method) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) DeleteResult(com.mongodb.client.result.DeleteResult)

Example 34 with DeleteResult

use of com.mongodb.client.result.DeleteResult in project gora by apache.

the class MongoStore method delete.

@Override
public boolean delete(final K key) throws GoraException {
    try {
        Document removeKey = new Document("_id", key);
        DeleteResult writeResult = mongoClientColl.deleteOne(removeKey);
        return writeResult.getDeletedCount() > 0;
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) Document(org.bson.Document) DeleteResult(com.mongodb.client.result.DeleteResult) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 35 with DeleteResult

use of com.mongodb.client.result.DeleteResult in project morphia by mongodb.

the class TestDatastore method testDeletes.

@Test
public void testDeletes() {
    for (int i = 0; i < 100; i++) {
        getDs().save(new City());
    }
    DeleteResult delete = getDs().find(City.class).delete();
    assertEquals(delete.getDeletedCount(), 1, "Should only delete 1");
    City first = getDs().find(City.class).first();
    delete = getDs().delete(first);
    assertEquals(delete.getDeletedCount(), 1, "Should only delete 1");
    first = getDs().find(City.class).first();
    delete = getDs().delete(first, new DeleteOptions().multi(true));
    assertEquals(delete.getDeletedCount(), 1, "Should only delete 1");
    delete = getDs().find(City.class).delete(new DeleteOptions().multi(true));
    assertTrue(delete.getDeletedCount() > 1, "Should the rest");
}
Also used : DeleteOptions(dev.morphia.DeleteOptions) FindAndDeleteOptions(dev.morphia.query.FindAndDeleteOptions) City(dev.morphia.test.models.City) DeleteResult(com.mongodb.client.result.DeleteResult) Test(org.testng.annotations.Test)

Aggregations

DeleteResult (com.mongodb.client.result.DeleteResult)46 Document (org.bson.Document)20 UpdateResult (com.mongodb.client.result.UpdateResult)10 BsonDocument (org.bson.BsonDocument)9 Test (org.junit.jupiter.api.Test)9 BasicDBObject (com.mongodb.BasicDBObject)7 WriteConcern (com.mongodb.WriteConcern)6 Bson (org.bson.conversions.Bson)6 MongoException (com.mongodb.MongoException)5 ArrayList (java.util.ArrayList)5 DataAccessException (org.springframework.dao.DataAccessException)5 MongoGridFSException (com.mongodb.MongoGridFSException)4 MongoClient (com.mongodb.client.MongoClient)4 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)4 ReadPreference (com.mongodb.ReadPreference)3 MongoDatabase (com.mongodb.client.MongoDatabase)3 InsertOneResult (com.mongodb.client.result.InsertOneResult)3 MongoClient (com.mongodb.reactivestreams.client.MongoClient)3 MongoDatabase (com.mongodb.reactivestreams.client.MongoDatabase)3 ObjectId (org.bson.types.ObjectId)3