List of usage examples for com.mongodb.client.model Filters gt
public static <TItem> Bson gt(final String fieldName, final TItem value)
From source file:io.mandrel.timeline.impl.MongoTimelineRepository.java
License:Apache License
@Override public void pool(Listener listener) { LocalDateTime date = LocalDateTime.now(); Bson query = Filters.gt("time", date); try {//from w w w . j a v a 2s . c o m while (true) { MongoCursor<Document> cursor = timeline.find(query).cursorType(CursorType.TailableAwait).iterator(); while (true) { if (!cursor.hasNext()) { if (cursor.getServerCursor() == null) { break; } continue; } Document result = cursor.next(); try { Event event = mapper.readValue(result.toJson(), Event.class); date = event.getTime(); listener.on(event); } catch (Exception e) { log.warn("Error while getting the event", e); } } query = Filters.gt("time", date); } } catch (Exception e) { log.warn("Event pool process is down!", e); } }
From source file:mongodb.clients.percunia.mongo.Restriction.java
License:Apache License
public static <T> Bson gt(String field, T value) { return Filters.gt(field, value); }
From source file:org.eclipse.ditto.services.thingsearch.persistence.read.criteria.visitors.CreateBsonPredicateVisitor.java
License:Open Source License
@Override public Function<String, Bson> visitGt(final Object value) { return fieldName -> Filters.gt(fieldName, value); }
From source file:org.eclipse.ditto.services.utils.persistence.mongo.streaming.MongoReadJournal.java
License:Open Source License
private Source<String, NotUsed> listJournalPidsAbove(final MongoCollection<Document> journal, final String start, final int batchSize, final Duration maxBackOff, final int maxRestarts) { final List<Bson> pipeline = new ArrayList<>(5); // optional match stage if (!start.isEmpty()) { pipeline.add(Aggregates.match(Filters.gt(PROCESSOR_ID, start))); }//w ww .ja va 2s .c o m // sort stage pipeline.add(Aggregates.sort(Sorts.ascending(PROCESSOR_ID))); // limit stage. It should come before group stage or MongoDB would scan the entire journal collection. pipeline.add(Aggregates.limit(batchSize)); // group stage pipeline.add(Aggregates.group("$" + PROCESSOR_ID)); // sort stage 2 -- order after group stage is not defined pipeline.add(Aggregates.sort(Sorts.ascending(ID))); final Duration minBackOff = Duration.ofSeconds(1L); final double randomFactor = 0.1; return RestartSource.onFailuresWithBackoff(minBackOff, maxBackOff, randomFactor, maxRestarts, () -> Source.fromPublisher(journal.aggregate(pipeline)).map(document -> document.getString(ID))); }
From source file:org.jnosql.diana.mongodb.document.DocumentQueryConversor.java
License:Open Source License
public static Bson convert(DocumentCondition condition) { Document document = condition.getDocument(); Object value = document.getValue().get(); switch (condition.getCondition()) { case EQUALS://from w ww . j a v a 2s . co m return Filters.eq(document.getName(), value); case GREATER_THAN: return Filters.gt(document.getName(), value); case GREATER_EQUALS_THAN: return Filters.gte(document.getName(), value); case LESSER_THAN: return Filters.lt(document.getName(), value); case LESSER_EQUALS_THAN: return Filters.lte(document.getName(), value); case IN: return Filters.in(document.getName(), value); case LIKE: return Filters.regex(document.getName(), value.toString()); case AND: List<Document> andList = condition.getDocument().getValue().get(new TypeReference<List<Document>>() { }); return Filters.and(andList.stream().map(d -> new BasicDBObject(d.getName(), d.getValue().get())) .toArray(BasicDBObject[]::new)); case OR: List<Document> orList = condition.getDocument().getValue().get(new TypeReference<List<Document>>() { }); return Filters.or(orList.stream().map(d -> new BasicDBObject(d.getName(), d.getValue().get())) .toArray(BasicDBObject[]::new)); default: throw new UnsupportedOperationException( "The condition " + condition.getCondition() + " is not supported from mongoDB diana driver"); } }
From source file:org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.java
License:Apache License
public static <T> Bson createFilter(String mongoDbField, T queryValue, ComparisonOperator comparator) { Bson filter = null;//ww w. j a v a 2s.c om if (queryValue != null) { if (queryValue instanceof String) { switch (comparator) { case EQUALS: filter = Filters.eq(mongoDbField, queryValue); break; case NOT_EQUALS: filter = Filters.ne(mongoDbField, queryValue); break; case EQUAL_IGNORE_CASE: filter = Filters.regex(mongoDbField, queryValue.toString(), "i"); break; case STARTS_WITH: filter = Filters.regex(mongoDbField, "^" + queryValue + "*"); break; case ENDS_WITH: filter = Filters.regex(mongoDbField, "*" + queryValue + "$"); break; case REGEX: filter = Filters.regex(mongoDbField, queryValue.toString()); break; case TEXT: filter = Filters.text(String.valueOf(queryValue)); break; default: break; } } else { switch (comparator) { case EQUALS: filter = Filters.eq(mongoDbField, queryValue); break; case NOT_EQUALS: filter = Filters.ne(mongoDbField, queryValue); break; case GREATER_THAN: filter = Filters.gt(mongoDbField, queryValue); break; case GREATER_THAN_EQUAL: filter = Filters.gte(mongoDbField, queryValue); break; case LESS_THAN: filter = Filters.lt(mongoDbField, queryValue); break; case LESS_THAN_EQUAL: filter = Filters.lte(mongoDbField, queryValue); break; default: break; } } } return filter; }
From source file:org.opencb.commons.datastore.mongodb.MongoDBQueryUtils.java
License:Apache License
/** * Generates a date filter.//from ww w .j a v a 2s .c om * * @param mongoDbField Mongo field. * @param dateValues List of 1 or 2 strings (dates). Only one will be expected when something like the following is passed: * =20171210, 20171210, >=20171210, >20171210, <20171210, <=20171210 * When 2 strings are passed, we will expect it to be a range such as: 20171201-20171210 * @param comparator Comparator value. * @param type Type of parameter. Expecting one of {@link QueryParam.Type#DATE} or {@link QueryParam.Type#TIMESTAMP} * @return the Bson query. */ private static Bson createDateFilter(String mongoDbField, List<String> dateValues, ComparisonOperator comparator, QueryParam.Type type) { Bson filter = null; Object date = null; if (QueryParam.Type.DATE.equals(type)) { date = convertStringToDate(dateValues.get(0)); } else if (QueryParam.Type.TIMESTAMP.equals(type)) { date = convertStringToDate(dateValues.get(0)).getTime(); } if (date != null) { switch (comparator) { case BETWEEN: if (dateValues.size() == 2) { Date to = convertStringToDate(dateValues.get(1)); if (QueryParam.Type.DATE.equals(type)) { filter = new Document(mongoDbField, new Document().append("$gte", date).append("$lt", to)); } else if (QueryParam.Type.TIMESTAMP.equals(type)) { filter = new Document(mongoDbField, new Document().append("$gte", date).append("$lt", to.getTime())); } } break; case EQUALS: filter = Filters.eq(mongoDbField, date); break; case GREATER_THAN: filter = Filters.gt(mongoDbField, date); break; case GREATER_THAN_EQUAL: filter = Filters.gte(mongoDbField, date); break; case LESS_THAN: filter = Filters.lt(mongoDbField, date); break; case LESS_THAN_EQUAL: filter = Filters.lte(mongoDbField, date); break; default: break; } } return filter; }
From source file:org.opencb.commons.datastore.mongodb.MongoPersistentCursor.java
License:Apache License
protected MongoPersistentCursor resume(Object lastObjectId) { Bson query;/*www . j a v a 2 s . c o m*/ if (lastObjectId != null) { query = Filters.and(Filters.gt("_id", lastObjectId), this.query); } else { query = this.query; } FindIterable<Document> iterable = newFindIterable(query, this.projection, this.options); if (!options.containsKey(QueryOptions.SORT)) { iterable.sort(Sorts.ascending("$natural")); } mongoCursor = iterable.batchSize(batchSize).limit(limit).skip(skip).iterator(); return this; }