/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values * @param readPreference {@link ReadPreference} to be used for this operation * @return a List of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName, final ReadPreference readPreference) { return distinct(fieldName, new BasicDBObject(), readPreference); }
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values * @param query specifies the selection query to determine the subset of documents from which to retrieve the distinct values * @return an array of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName, final DBObject query) { return distinct(fieldName, query, getReadPreference()); }
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values. * @return a List of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName) { return distinct(fieldName, getReadPreference()); }
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values * @param query specifies the selection query to determine the subset of documents from which to retrieve the distinct values * @param readPreference {@link ReadPreference} to be used for this operation * @return A {@code List} of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName, final DBObject query, final ReadPreference readPreference) { return distinct(fieldName, new DBCollectionDistinctOptions().filter(query).readPreference(readPreference)); }
DBCollection dBCollection = datastore.getCollection(MyEntity.class); List id=dBCollection.distinct("id",dbObject);
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values * @param readPreference {@link ReadPreference} to be used for this operation * @return a List of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName, final ReadPreference readPreference) { return distinct(fieldName, new BasicDBObject(), readPreference); }
@Override public Iterator<String> getDomainsIterator() { @SuppressWarnings("unchecked") List<String> domains = (List<String>) collection.distinct(FIELD_DOMAIN); return domains.iterator(); }
DBCollection coll = db.getCollection("your_collection"); List<String> lst=coll.distinct("your_property"); for(String l:lst){ BasicDBObject query = new BasicDBObject("your_property", l); DBObject object=coll.findOne(query); System.out.println(object); }
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values. * @return a List of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName) { return distinct(fieldName, getReadPreference()); }
/** * find distinct values for a key * * @param key The key * @param query query to match * @return The results */ public List distinct(String key, DBObject query) { return dbCollection.distinct(key, serializeFields(query)); }
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values * @param query specifies the selection query to determine the subset of documents from which to retrieve the distinct values * @return an array of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName, final DBObject query) { return distinct(fieldName, query, getReadPreference()); }
/** * find distinct values for a key * * @param key * The key * @param query * query to match * @return The results */ public List distinct(String key, DBObject query) { return dbCollection.distinct(key, serializeFields(query)); }
/** * find distinct values for a key * * @param key The key * @param query query to match * @return The results */ public List distinct(String key, DBObject query) { return dbCollection.distinct(key, serializeFields(query)); }
/** * distinct() on large collection will fail. you should use distinctLarge(). * @param key * @return */ public List distinct(String key){ return dao.getCollection().distinct(key, condition); }
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * distinct() on large collection will fail. you should use distinctLarge(). * @param key * @return */ public List distinct(String key){ return getCollection().distinct(key); }
@Override public List<String> queryApplicationOptionsIn(ThemeQuestionQueryParameters parameters) { List<Object> distinctApplicationOptions = getCollection().distinct(FIELD_APPLICATION_OPTION, buildQuery(parameters)[0]); LOGGER.debug("Got " + distinctApplicationOptions.size() + " application options "); ArrayList<String> results = new ArrayList<String>(); for (Object value : distinctApplicationOptions){ LOGGER.debug("Got option " + value); results.add((String) value); } return results; }
/** * Find the distinct values for a specified field across a collection and returns the results in an array. * * @param fieldName Specifies the field for which to return the distinct values * @param query specifies the selection query to determine the subset of documents from which to retrieve the distinct values * @param readPreference {@link ReadPreference} to be used for this operation * @return A {@code List} of the distinct values * @mongodb.driver.manual reference/command/distinct Distinct Command */ public List distinct(final String fieldName, final DBObject query, final ReadPreference readPreference) { return distinct(fieldName, new DBCollectionDistinctOptions().filter(query).readPreference(readPreference)); }
@SuppressWarnings("unchecked") public <T> List<T> distinct(MorphiaQuery q, String field) { return collection().distinct(field, q.morphiaQuery().getQueryObject()); }