public List<ObjectId> getIds(User user) { DBObject group = MongoUtils.group(new BasicDBObject(ID, MongoUtils.valueOf(MongoMeasurement.SENSOR, ID))); DBObject match = MongoUtils.match(MongoMeasurement.USER, ref(user)); AggregationOutput result = getMongoDB().getDatastore().getCollection(MongoMeasurement.class).aggregate(match, group); result.getCommandResult().throwOnError(); return StreamSupport.stream(result.results().spliterator(), false) .map(x -> (ObjectId) x.get(ID)) // .map(x -> new Key<>(MongoSensor.class, x)) .collect(Collectors.toList()); }
private Query<MongoSensor> applyFilters(Query<MongoSensor> q, Set<PropertyFilter> filters) { if (filters == null || filters.isEmpty()) { return q; } Multimap<String, Object> map = LinkedListMultimap.create(); for (PropertyFilter f : filters) { String field = f.getField(); String value = f.getValue(); // "123" != 123 && "true" != true in MongoDB... if (field != null && value != null) { field = MongoUtils.path(MongoSensor.PROPERTIES, field); if (isTrue(value)) { map.put(field, true); } else if (isFalse(value)) { map.put(field, false); } else if (isNumeric(value)) { map.put(field, Double.valueOf(value)); } else { map.put(field, value); } } } q.disableValidation(); map.keySet() .stream() .forEach( (field) -> { q.field(field).in(map.get(field)); }); return q.enableValidation(); }
@Override public TermsOfUse get(Pagination p) { return fetch(q().order(MongoUtils.reverse(MongoTermsOfUseInstance.CREATION_DATE)), p); }