本文整理汇总了Java中com.mongodb.client.result.DeleteResult.getDeletedCount方法的典型用法代码示例。如果您正苦于以下问题:Java DeleteResult.getDeletedCount方法的具体用法?Java DeleteResult.getDeletedCount怎么用?Java DeleteResult.getDeletedCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.client.result.DeleteResult
的用法示例。
在下文中一共展示了DeleteResult.getDeletedCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteById
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
/**
* 删除记录
*
* @param collectionName
* 表名
* @param mongoObj
* 记录
* @return
*/
public static boolean deleteById(String collectionName, MongoObj mongoObj) {
MongoCollection<Document> collection = getCollection(collectionName);
try {
Bson filter = Filters.eq(MongoConfig.MONGO_ID, mongoObj.getDocument().getObjectId(MongoConfig.MONGO_ID));
DeleteResult result = collection.deleteOne(filter);
if (result.getDeletedCount() == 1) {
return true;
} else {
return false;
}
} catch (Exception e) {
if (log != null) {
log.error("删除记录失败", e);
}
return false;
}
}
示例2: delete
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
/**
* Delete the data in mongo by the query.
*
* @param collection
* the collection
* @param q
* the q
* @param db
* the db
* @return the long
*/
public int delete(String collection, W q, String db) {
int n = -1;
try {
MongoCollection<Document> db1 = getCollection(db, collection);
if (db != null) {
DeleteResult r = db1.deleteMany(q.query());
// db.remove(query);
n = (int) r.getDeletedCount();
}
if (log.isDebugEnabled()) {
log.debug("delete, collection=" + collection + ", q=" + q + ", deleted=" + n);
}
} catch (Exception e) {
if (log.isErrorEnabled())
log.error(e.getMessage(), e);
}
return n;
}
示例3: deletePointsFromSeriesByPointKey
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public boolean deletePointsFromSeriesByPointKey(String key, List<String> pointKeys) {
MongoCollection<Document> collection = getCollection(key);
boolean ret = false;
for (String pointKey : pointKeys) {
Document victim = new Document(ROWKEY, key).append(COLKEY, pointKey);
try {
DeleteResult result = collection.deleteMany(victim);
log.info("Removed " + result.getDeletedCount() + " rows");
ret = (result.getDeletedCount() > 0);
} catch (MongoException me) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, new ExceptionToString(me));
}
}
return ret;
}
示例4: removeSuite
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public boolean removeSuite(DBKey dbKey, String correlationId, Long version)
throws StorageException {
LOGGER
.debug("Removing suite with correlationId {}, version {} from {}.", correlationId, version,
dbKey);
MongoCollection<Document> metadata = getMetadataCollection(dbKey);
final DeleteResult deleteResult = metadata.deleteOne(
Filters.and(
Filters.eq(CORRELATION_ID_PARAM_NAME, correlationId),
Filters.eq(SUITE_VERSION_PARAM_NAME, version)
));
return deleteResult.getDeletedCount() == 1;
}
示例5: deleteById
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
public static int deleteById(MongoCollection<Document> col, Object id) {
int count = 0;
Bson filter = Filters.eq("_id", id);
DeleteResult deleteResult = col.deleteOne(filter);
count = (int) deleteResult.getDeletedCount();
return count;
}
示例6: executeQuery
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
long executeQuery(int threadId, long threadRunCount, long globalRunCount, long selectorId, long randomId) {
final DeleteResult res = THREAD_RUN_COUNT.equals(queriedField)?mongoCollection.deleteMany(eq(queriedField, selectorId))
:ID.equals(queriedField)?mongoCollection.deleteOne(eq(queriedField, selectorId)):null;
return res!=null?res.getDeletedCount():0l;
}
示例7: delete
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public void delete(String oid) throws DataNotFoundException {
DeleteResult deleteResult = this.collection.deleteOne(eq("_id", new ObjectId(oid)));
if (deleteResult.getDeletedCount() == 0) {
throw new DataNotFoundException(new Throwable("File with id " + oid + " not found"));
}
}
示例8: delete
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public void delete(String name) throws DataNotFoundException {
BasicDBObject query = new BasicDBObject();
query.put("objectType", "ActivityCategory");
query.put("name", name);
DeleteResult deleteResult = collection.deleteOne(query);
if (deleteResult.getDeletedCount() == 0) {
throw new DataNotFoundException(
new Throwable("ActivityCategory {" + name + "} not found.")); }
}
示例9: delete
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public void delete(String id) throws DataNotFoundException {
DeleteResult deleteResult = collection.deleteOne(eq("code", id));
if (deleteResult.getDeletedCount() == 0) {
throw new DataNotFoundException(new Throwable("Exam Lot does not exist"));
}
}
示例10: delete
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public void delete(String id) throws DataNotFoundException{
DeleteResult deleteResult = collection.deleteOne(eq("code", id));
if (deleteResult.getDeletedCount() == 0) {
throw new DataNotFoundException(new Throwable("Transportation Lot does not exist"));
}
}
示例11: delete
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public <T> void delete(T t) {
MongoModel mongoModel = (MongoModel) t;
MongoCollection<Document> collection = database.getCollection(t.getClass().getSimpleName());
BasicDBObject query = new BasicDBObject(MongoModel.OID, mongoModel.getObjectId());
DeleteResult deleteResult = collection.deleteOne(query);
if (deleteResult.getDeletedCount() != 1) {
Log.error("error while deleting from db, total delete count: " + deleteResult.getDeletedCount());
}
}
示例12: deleteDocument
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
public static void deleteDocument(Bson filter, Optional<String> hash, MongoCollection<Document> collection) {
if (hash.isPresent()) {
filter = Filters.and(
filter,
Filters.eq("meta.hash", hash.get())
);
}
final DeleteResult result = collection.deleteOne(filter);
if (result.getDeletedCount() != 1) {
throw new WebApplicationException("Concurrent modification", 422);
}
}
示例13: deletePointsFromSeries
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public boolean deletePointsFromSeries(String key) {
boolean ret = false;
MongoCollection<Document> collection = getCollection(key);
Document victim = new Document(ROWKEY, key);
try {
DeleteResult result = collection.deleteMany(victim);
log.info("Removed " + result.getDeletedCount() + " rows");
ret = (result.getDeletedCount() > 0);
} catch (MongoException me) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, new ExceptionToString(me));
}
unregisterKey(key);
return ret;
}
示例14: deleteBlob
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
@Override
public Boolean deleteBlob(CallingContext context, String docPath) {
log.debug("Removing " + docPath);
Document query = new Document();
query.append(BLOB_NAME, docPath);
try {
DeleteResult res = getCollection().deleteOne(query);
return res.getDeletedCount() != 0;
} catch (MongoException e) {
log.error("Could not delete " + docPath + ": " + e.getMessage());
log.debug(ExceptionToString.format(e));
}
return false;
}
示例15: releaseLockWithID
import com.mongodb.client.result.DeleteResult; //导入方法依赖的package包/类
private Boolean releaseLockWithID(String lockName, String id) {
Document lockFileQuery = new Document();
lockFileQuery.put("_id", id);
MongoCollection<Document> coll = getLockCollection(lockName);
DeleteResult res = coll.deleteOne(lockFileQuery);
return (res.getDeletedCount() == 1);
}