com.mongodb.client.DistinctIterable Java Examples

The following examples show how to use com.mongodb.client.DistinctIterable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoDepositServiceImpl.java    From nuls-v2 with MIT License 5 votes vote down vote up
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;
}
 
Example #2
Source File: NamespaceSynchronizationConfig.java    From stitch-android-sdk with Apache License 2.0 5 votes vote down vote up
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();
  }
}
 
Example #3
Source File: MongoModuleProjectionRepository.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example #4
Source File: MongoTechnoProjectionRepository.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example #5
Source File: MongoCollectionDistinct.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
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;
	}
}
 
Example #6
Source File: IMongoSession.java    From ymate-platform-v2 with Apache License 2.0 votes vote down vote up
<T extends IEntity, RESULT> DistinctIterable<RESULT> distinct(Class<T> entity, Class<RESULT> resultClass, String fieldName) throws Exception; 
Example #7
Source File: IMongoSession.java    From ymate-platform-v2 with Apache License 2.0 votes vote down vote up
<T extends IEntity, RESULT> DistinctIterable<RESULT> distinct(Class<T> entity, Class<RESULT> resultClass, String fieldName, Query query) throws Exception;