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);
}
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;
}
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());
}
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);
}
}
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");
}
Aggregations