类com.mongodb.client.DistinctIterable源码实例Demo

下面列出了怎么用com.mongodb.client.DistinctIterable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: nuls-v2   文件: MongoDepositServiceImpl.java
public List<String> getAgentHashList(int chainId, String address) {
    Bson bson = Filters.and(Filters.eq("address", address), Filters.eq("type", 0), Filters.eq("deleteHeight", 0));
    DistinctIterable<String> iterable = mongoDBService.getCollection(DEPOSIT_TABLE + chainId).distinct("agentHash", bson, String.class);
    List<String> list = new ArrayList<>();
    MongoCursor<String> mongoCursor = iterable.iterator();
    while (mongoCursor.hasNext()) {
        list.add(mongoCursor.next());
    }
    return list;
}
 
Set<BsonValue> getStaleDocumentIds() {
  nsLock.readLock().lock();
  try {
    if (this.namespacesColl.count(
        getNsFilter(getNamespace())
            .append(ConfigCodec.Fields.IS_STALE, new BsonBoolean(true))
    ) != 0) {
      // If the entire namespace is stale, return all the document ids in the namespace that
      // are not paused.
      final DistinctIterable<BsonValue> unpausedStaleDocIds = this.docsColl.distinct(
          CoreDocumentSynchronizationConfig.ConfigCodec.Fields.DOCUMENT_ID_FIELD,
          getNsFilter(getNamespace()).append(
              CoreDocumentSynchronizationConfig.ConfigCodec.Fields.IS_PAUSED, BsonBoolean.FALSE),
          BsonValue.class);
      return unpausedStaleDocIds.into(new HashSet<>());
    } else {
      // Return just the stale documents that have been marked stale because they were
      // individually unpaused and marked as stale.
      final DistinctIterable<BsonValue> staleDocIds = this.docsColl.distinct(
          CoreDocumentSynchronizationConfig.ConfigCodec.Fields.DOCUMENT_ID_FIELD,
          getNsFilter(getNamespace()).append(
              CoreDocumentSynchronizationConfig.ConfigCodec.Fields.IS_STALE, BsonBoolean.TRUE),
          BsonValue.class);
      return staleDocIds.into(new HashSet<>());
    }
  } finally {
    nsLock.readLock().unlock();
  }
}
 
@QueryHandler
@Override
@Timed
public List<String> onGetModulesNameQuery(GetModulesNameQuery query) {
    final DistinctIterable<String> iterable = mongoTemplate.getCollection(MODULE).distinct("key.name", String.class);
    return StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList());
}
 
@QueryHandler
@Override
@Timed
public List<String> onGetTechnosNameQuery(GetTechnosNameQuery query) {
    final DistinctIterable<String> iterable = mongoTemplate.getCollection(TECHNO).distinct("key.name", String.class);
    return StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList());
}
 
源代码5 项目: openbd-core   文件: MongoCollectionDistinct.java
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
	MongoDatabase db = getMongoDatabase( _session, argStruct );

	String collection = getNamedStringParam( argStruct, "collection", null );
	if ( collection == null )
		throwException( _session, "please specify a collection" );

	String key = getNamedStringParam( argStruct, "key", null );
	if ( key == null )
		throwException( _session, "please specify a key" );

	cfData query = getNamedParam( argStruct, "query", null );

	try {

		DistinctIterable<String> result;
		if ( query != null )
			result = db.getCollection( collection ).distinct( key, String.class ).filter( getDocument( query ) );
		else
			result = db.getCollection( collection ).distinct( key, String.class );

		cfArrayData arr = cfArrayData.createArray( 1 );

		result.forEach( new Block<String>() {

			@Override
			public void apply( final String st ) {
				try {
					arr.addElement( new cfStringData( st ) );
				} catch ( cfmRunTimeException e ) {}
			}
		} );


		return arr;

	} catch ( MongoException me ) {
		throwException( _session, me.getMessage() );
		return null;
	}
}
 
源代码6 项目: ymate-platform-v2   文件: IMongoSession.java
<T extends IEntity, RESULT> DistinctIterable<RESULT> distinct(Class<T> entity, Class<RESULT> resultClass, String fieldName) throws Exception; 
源代码7 项目: ymate-platform-v2   文件: IMongoSession.java
<T extends IEntity, RESULT> DistinctIterable<RESULT> distinct(Class<T> entity, Class<RESULT> resultClass, String fieldName, Query query) throws Exception; 
 类所在包
 类方法
 同包方法