当前位置: 首页>>代码示例>>Java>>正文


Java DeleteResult类代码示例

本文整理汇总了Java中com.mongodb.client.result.DeleteResult的典型用法代码示例。如果您正苦于以下问题:Java DeleteResult类的具体用法?Java DeleteResult怎么用?Java DeleteResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DeleteResult类属于com.mongodb.client.result包,在下文中一共展示了DeleteResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteManyDocument

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
/**
 * This is deleted delete all document(s), which is matched
 */
@Override
public void deleteManyDocument() {
	MongoDatabase db = null;
	MongoCollection collection = null;
	Bson query = null;
	try {
		db = client.getDatabase(mongo.getDataBase());
		collection = db.getCollection(mongo.getSampleCollection());
		query = lt("age", 20);
		DeleteResult result = collection.deleteMany(query);
		if (result.wasAcknowledged()) {
			log.info("Document deleted successfully \nNo of Document(s) Deleted : "
					+ result.getDeletedCount());
		}
	} catch (MongoException e) {
		log.error("Exception occurred while delete Many Document : " + e, e);
	}
}
 
开发者ID:sundarcse1216,项目名称:mongodb-crud,代码行数:22,代码来源:DeleteDocumentsImpl.java

示例2: shouldDeleteSession

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
@Test
public void shouldDeleteSession() throws Exception {
	
	// given
	String sessionId = UUID.randomUUID().toString();

	Document sessionDocument = new Document();

	given(this.mongoOperations.findById(eq(sessionId), eq(Document.class),
		eq(ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME))).willReturn(Mono.just(sessionDocument));
	given(this.mongoOperations.remove((Mono<? extends Object>) any(), eq("sessions"))).willReturn(Mono.just(DeleteResult.acknowledged(1)));

	// when
	StepVerifier.create(this.repository.deleteById(sessionId))
		.expectNextMatches(aVoid -> {
			// then
			verify(this.mongoOperations).remove(any(Document.class),
				eq(ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME));
			return true;
		});
}
 
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:22,代码来源:ReactiveMongoOperationsSessionRepositoryTest.java

示例3: deleteOneDocument

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
/**
 * This is delete the single document, which is first matched
 */
@Override
public void deleteOneDocument() {
	MongoDatabase db = null;
	MongoCollection collection = null;
	Bson query = null;
	try {
		db = client.getDatabase(mongo.getDataBase());
		collection = db.getCollection(mongo.getSampleCollection());
		query = eq("name", "sundar");
		DeleteResult result = collection.deleteMany(query);
		if (result.wasAcknowledged()) {
			log.info("Single Document deleted successfully \nNo of Document Deleted : " + result.getDeletedCount());
		}
	} catch (MongoException e) {
		log.error("Exception occurred while delete Single Document : " + e, e);
	}
}
 
开发者ID:sundarcse1216,项目名称:mongodb-crud,代码行数:21,代码来源:DeleteDocumentsImpl.java

示例4: 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;
	}

}
 
开发者ID:dianbaer,项目名称:grain,代码行数:28,代码来源:MongodbManager.java

示例5: 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;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:31,代码来源:MongoHelper.java

示例6: deleteMany

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
@Override
public DeleteResult deleteMany(Bson filter)
{
    OperationMetric metric = null;
    if (MongoLogger.GATHERER.isEnabled())
    {
        List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
        String operationName = "Mongo : " + getNamespace().getCollectionName() + " : deleteMany " +
            MongoUtilities.filterParameters(filter).toString();
        metric = startMetric(operationName, keyValuePairs);
        addWriteConcern(metric);
    }

    DeleteResult retVal = collection.deleteMany(filter);

    stopMetric(metric, (int) retVal.getDeletedCount());

    return retVal;
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:20,代码来源:ProfiledMongoCollection.java

示例7: deleteOne

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
@Override
public DeleteResult deleteOne(Bson filter)
{
    OperationMetric metric = null;
    if (MongoLogger.GATHERER.isEnabled())
    {
        List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
        String operationName = "Mongo : " + getNamespace().getCollectionName() + " : deleteOne " +
            MongoUtilities.filterParameters(filter).toString();
        metric = startMetric(operationName, keyValuePairs);
        addWriteConcern(metric);
    }

    DeleteResult retVal = collection.deleteOne(filter);

    stopMetric(metric, (int) retVal.getDeletedCount());

    return retVal;
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:20,代码来源:ProfiledMongoCollection.java

示例8: 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;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:MongoSeriesStore.java

示例9: delete

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
public CompletableFuture<SecurityDefinitionStore> delete(
    SecurityDefinitionRequest securityDefinitionRequest) {

  CompletableFuture<SecurityDefinitionStore> future =
          new CompletableFuture<>();

  // todo: handle different request types
  collection.deleteMany(eq("symbol", securityDefinitionRequest.getSymbol()),
      (DeleteResult result, final Throwable t) -> {
        if (t == null) {
          future.complete(this);
        } else {
          future.completeExceptionally(t);
        }
      });
  return future;
}
 
开发者ID:FIXTradingCommunity,项目名称:timpani,代码行数:18,代码来源:MongoDBSecurityDefinitionStore.java

示例10: 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;
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:17,代码来源:MetadataDAOMongoDBImpl.java

示例11: removeTilesWithIds

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
public void removeTilesWithIds(final StackId stackId,
                               final List<String> tileIds)
        throws IllegalArgumentException {

    MongoUtil.validateRequiredParameter("stackId", stackId);
    MongoUtil.validateRequiredParameter("tileIds", tileIds);

    final MongoCollection<Document> tileCollection = getTileCollection(stackId);
    final Document tileQuery = new Document("tileId",
                                            new Document(QueryOperators.IN,
                                                         tileIds));
    final Document tileQueryForLog = new Document("tileId",
                                                  new Document(QueryOperators.IN,
                                                               Arrays.asList("list of",
                                                                             tileIds.size() + " tileIds")));
    final DeleteResult removeResult = tileCollection.deleteMany(tileQuery);

    LOG.debug("removeTilesWithIds: {}.remove({}) deleted {} document(s)",
              MongoUtil.fullName(tileCollection), tileQueryForLog.toJson(), removeResult.getDeletedCount());
}
 
开发者ID:saalfeldlab,项目名称:render,代码行数:21,代码来源:RenderDao.java

示例12: removeMatchesInvolvingObject

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
public void removeMatchesInvolvingObject(final MatchCollectionId collectionId,
                                         final String groupId,
                                         final String id)
        throws IllegalArgumentException, ObjectNotFoundException {

    LOG.debug("removeMatchesInvolvingObject: entry, collectionId={}, groupId={}, id={}",
              collectionId, groupId, id);

    final MongoCollection<Document> collection = getExistingCollection(collectionId);

    MongoUtil.validateRequiredParameter("groupId", groupId);
    MongoUtil.validateRequiredParameter("id", id);

    final Document query = getInvolvingObjectQuery(groupId, id);

    final DeleteResult result = collection.deleteMany(query);

    LOG.debug("removeMatchesInvolvingObject: removed {} matches using {}.delete({})",
              result.getDeletedCount(), MongoUtil.fullName(collection), query.toJson());
}
 
开发者ID:saalfeldlab,项目名称:render,代码行数:21,代码来源:MatchDao.java

示例13: removeMatchesBetweenGroups

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
public void removeMatchesBetweenGroups(final MatchCollectionId collectionId,
                                       final String pGroupId,
                                       final String qGroupId)
        throws IllegalArgumentException, ObjectNotFoundException {

    LOG.debug("removeMatchesBetweenGroups: entry, collectionId={}, pGroupId={}, qGroupId={}",
              collectionId, pGroupId,  qGroupId);

    final MongoCollection<Document> collection = getExistingCollection(collectionId);

    MongoUtil.validateRequiredParameter("pGroupId", pGroupId);
    MongoUtil.validateRequiredParameter("qGroupId", qGroupId);

    final String noTileId = "";
    final CanvasMatches normalizedCriteria = new CanvasMatches(pGroupId, noTileId, qGroupId, noTileId, null);
    final Document query = new Document(
            "pGroupId", normalizedCriteria.getpGroupId()).append(
            "qGroupId", normalizedCriteria.getqGroupId());

    final DeleteResult result = collection.deleteMany(query);

    LOG.debug("removeMatchesBetweenGroups: removed {} matches using {}.delete({})",
              result.getDeletedCount(), MongoUtil.fullName(collection), query.toJson());
}
 
开发者ID:saalfeldlab,项目名称:render,代码行数:25,代码来源:MatchDao.java

示例14: doDelete

import com.mongodb.client.result.DeleteResult; //导入依赖的package包/类
protected final FluentFuture<Integer> doDelete(
    final Constraints.ConstraintHost criteria) {
  checkNotNull(criteria);
  return submit(new Callable<DeleteResult>() {
    @Override
    public DeleteResult call() {
      return collection().deleteMany(convertToBson(criteria));
    }
  }).lazyTransform(new Function<DeleteResult, Integer>() {
    @Override
    public Integer apply(DeleteResult input) {
      return (int) input.getDeletedCount();
    }
  });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:Repositories.java

示例15: 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;
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:8,代码来源:MongoCRUD.java


注:本文中的com.mongodb.client.result.DeleteResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。