List of usage examples for com.mongodb.client.model Filters exists
public static Bson exists(final String fieldName)
From source file:com.jaeksoft.searchlib.crawler.cache.MongoDbCrawlCache.java
License:Open Source License
@Override public long flush(long expiration) throws IOException { rwl.r.lock();//from w ww .j av a 2 s . com try { final Bson filter = expiration == 0 ? Filters.exists("uri") : Filters.lt("_id", new ObjectId(new Date(expiration))); indexedCollection.deleteMany(filter); for (GridFSFile f : contentGrid.find(filter)) contentGrid.delete(f.getObjectId()); long l = metaCollection.deleteMany(filter).getDeletedCount(); return l; } finally { rwl.r.unlock(); } }
From source file:io.lumeer.storage.mongodb.dao.collection.MongoDataDao.java
License:Open Source License
private Bson createFilter(String collectionId, SearchQuery query) { List<Bson> filters = new ArrayList<>(); // does not work as expected - cannot search for a single character for example, only whole words if (query.isFulltextQuery()) { Collection collection = collectionDao.getCollectionById(collectionId); List<Attribute> fulltextAttrs = collection.getAttributes().stream() .filter(attr -> attr.getName().toLowerCase().contains(query.getFulltext().toLowerCase())) .collect(Collectors.toList()); // we only search by presence of the matching attributes if (fulltextAttrs.size() > 0) { filters.add(Filters.or(fulltextAttrs.stream().map(attr -> Filters.exists(attr.getId())) .collect(Collectors.toList()))); } else if (collection.getAttributes().size() > 0) { // we search by content filters.add(Filters.or(collection.getAttributes().stream() .map(attr -> Filters.regex(attr.getId(), query.getFulltext(), "i")) .collect(Collectors.toList()))); }/*from ww w . ja v a2s . c o m*/ } if (query.isDocumentIdsQuery()) { List<ObjectId> ids = query.getDocumentIds().stream().filter(ObjectId::isValid).map(ObjectId::new) .collect(Collectors.toList()); if (!ids.isEmpty()) { filters.add(Filters.in(ID, ids)); } } if (query.isFiltersQuery()) { List<Bson> attributeFilters = query.getFilters().stream().map(this::attributeFilter) .filter(Objects::nonNull).collect(Collectors.toList()); filters.addAll(attributeFilters); } final Bson result = filters.size() > 0 ? Filters.and(filters) : new Document(); return result; }
From source file:org.dcache.sf.FlushTask.java
License:Open Source License
@Override public Set<URI> poll() throws URISyntaxException { FindIterable<Document> result = files .find(Filters.and(Filters.eq("pnfsid", pnfsId.getId()), Filters.exists("bfid"))); final Set<URI> uris = new HashSet<>(); result.forEach(new Block<Document>() { @Override// w ww .j a va 2 s . co m public void apply(Document document) { try { String uriString = document.get("bfid").toString(); uris.add(new URI(uriString)); } catch (URISyntaxException e) { System.out.println(e.getMessage()); } } }); return uris; }
From source file:org.eclipse.ditto.services.thingsearch.persistence.read.expression.visitors.GetExistsBsonVisitor.java
License:Open Source License
@Override Bson visitRootLevelField(final String fieldName) { return Filters.exists(fieldName); }
From source file:twitterapp.TweetsProcessing.java
/** * @param args the command line arguments *//*www . j a va 2 s . com*/ public static void main(String[] args) throws JSONException { //createSeparateEntities(); //create the collections with the separate entities that are extracted from the tweet collections //creating separate collections from the entities (hashtags collection, mentioned collection etc) String[] collections = { "separateEntities", "separateEntities2", "separateEntities3", "separateEntities4" }; for (int p = 0; p < collections.length; p++) { MongoClient mongo = new MongoClient("localhost", 27017); MongoDatabase database = mongo.getDatabase("myTweetdb"); int counterHashtag = 0; int counterMentioned = 0; int counterUrl = 0; int counterRetweeted = 0; Bson filter = Filters.exists("hashtag"); MongoCollection<Document> h = database.getCollection("hashtagAll"); Iterator<Document> h2 = database.getCollection(collections[p]).find(filter).iterator(); while ((h2.hasNext()) && (counterHashtag < 250)) { Document doc = h2.next(); h.insertOne(doc); counterHashtag++; } filter = Filters.exists("mentioned_users"); MongoCollection<Document> m = database.getCollection("mentionedAll"); h2 = database.getCollection(collections[p]).find(filter).iterator(); while ((h2.hasNext()) && (counterMentioned < 250)) { Document doc = h2.next(); m.insertOne(doc); counterMentioned++; } filter = Filters.exists("url"); MongoCollection<Document> u = database.getCollection("urlAll"); h2 = database.getCollection(collections[p]).find(filter).iterator(); while ((h2.hasNext()) && (counterUrl < 250)) { Document doc = h2.next(); u.insertOne(doc); counterUrl++; } filter = Filters.exists("retweeted_tweet"); MongoCollection<Document> r = database.getCollection("retweetedAll"); h2 = database.getCollection(collections[p]).find(filter).iterator(); while ((h2.hasNext()) && (counterRetweeted < 250)) { Document doc = h2.next(); r.insertOne(doc); counterRetweeted++; } } }