List of usage examples for com.mongodb.client.model Projections include
public static Bson include(final List<String> fieldNames)
From source file:com.epam.dlab.backendapi.dao.ExploratoryLibDAO.java
License:Apache License
/** * Finds and returns the status of library. * * @param user user name./* www . j av a 2 s. c om*/ * @param exploratoryName the name of exploratory. * @param libraryGroup the group name of library. * @param libraryName the name of library. */ public LibStatus fetchLibraryStatus(String user, String exploratoryName, String libraryGroup, String libraryName, String version) { Optional<Document> libraryStatus = findOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), libraryConditionExploratory(libraryGroup, libraryName, version)), Projections.fields(excludeId(), Projections.include("libs.status"))); if (libraryStatus.isPresent()) { Object lib = libraryStatus.get().get(EXPLORATORY_LIBS); if (lib instanceof List && !((List) lib).isEmpty()) { return LibStatus.of(((List<Document>) lib).get(0).getOrDefault(STATUS, EMPTY).toString()); } } return LibStatus.of(EMPTY); }
From source file:com.epam.dlab.billing.azure.AzureBillingDetailsService.java
License:Apache License
public void updateBillingDetails() { final List<String> users = new ArrayList<>(); FindIterable<Document> iterable = mongoDbBillingClient.getDatabase() .getCollection(MongoKeyWords.EDGE_COLLECTION).find() .projection(Projections.include(MongoKeyWords.MONGO_ID)); for (Document document : iterable) { String user = document.getString(MongoKeyWords.MONGO_ID); if (StringUtils.isNotEmpty(user)) { users.add(user);/*from ww w . j a v a 2 s.co m*/ } else { log.warn("Empty user is found"); } } if (!users.isEmpty()) { users.forEach(this::updateBillingDetails); } else { log.warn("No users found"); } }
From source file:com.hazelcast.loader.MongoMapStore.java
License:Open Source License
@Override public Iterable<String> loadAllKeys() { System.out.println("LoadAllKeys"); List<String> keys = new LinkedList<String>(); FindIterable<Document> ids = collection.find().projection(Projections.include("_id")); for (Document document : ids) { keys.add(document.get("_id").toString()); }//w w w .j a v a 2s .com return keys; }
From source file:com.px100systems.data.plugin.storage.mongo.MongoDatabaseStorage.java
License:Open Source License
public Long getMaxId(String unitName) { MongoDatabase db = mongoClient.getDatabase(databaseName); Document result = db.getCollection(unitName).find().sort(Sorts.descending("id")) .projection(Projections.include("id")).limit(1).first(); if (result == null) return null; return result.getLong("id"); }
From source file:com.spleefleague.core.listeners.EnvironmentListener.java
@EventHandler(priority = EventPriority.HIGH) public void rankCheck(AsyncPlayerPreLoginEvent e) { Document dbo = SpleefLeague.getInstance().getPluginDB().getCollection("Players") .find(new Document("uuid", e.getUniqueId().toString())) .projection(Projections.fields(Projections.include("rank"), Projections.excludeId())).first(); if (dbo != null) { Rank rank = Rank.DEFAULT;//from ww w . j av a 2s . c o m try { rank = Rank.valueOf(dbo.getString("rank")); } catch (Exception ignored) { } if (rank == null || (!rank.hasPermission(SpleefLeague.getInstance().getMinimumJoinRank()) && !SpleefLeague.getInstance().getExtraJoinRanks().contains(rank))) { e.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_WHITELIST); e.setKickMessage(ChatColor.RED + "You are not of rank to join this server!"); } } }
From source file:io.lumeer.storage.mongodb.dao.project.MongoViewDao.java
License:Open Source License
@Override public Set<String> getAllViewCodes() { return databaseCollection().find().projection(Projections.include(ViewCodec.CODE)).into(new ArrayList<>()) .stream().map(Resource::getCode).collect(Collectors.toSet()); }
From source file:io.lumeer.storage.mongodb.MongoDbStorage.java
License:Open Source License
@Override public DataDocument readDocumentIncludeAttrs(final String collectionName, final DataFilter filter, final List<String> attributes) { Document document = database.getCollection(collectionName).find(filter.<Bson>get()) .projection(Projections.include(attributes)).limit(1).first(); return document != null ? MongoUtils.convertDocument(document) : null; }
From source file:io.lumeer.storage.mongodb.MongoDbStorage.java
License:Open Source License
@Override public List<DataDocument> search(String collectionName, DataFilter filter, final DataSort sort, List<String> attributes, final int skip, int limit) { MongoCollection<Document> collection = database.getCollection(collectionName); FindIterable<Document> documents = filter != null ? collection.find(filter.<Bson>get()) : collection.find(); if (sort != null) { documents = documents.sort(sort.<Bson>get()); }// w w w . ja v a2 s. com if (attributes != null && !attributes.isEmpty()) { documents.projection(Projections.fields(Projections.include(attributes))); } if (skip > 0) { documents = documents.skip(skip); } if (limit > 0) { documents = documents.limit(limit); } return MongoUtils.convertIterableToList(documents); }
From source file:io.mandrel.metadata.impl.MongoMetadataStore.java
License:Apache License
@Override public Set<Uri> deduplicate(Collection<Uri> uris) { Set<Uri> temp = Sets.newHashSet(uris); Set<Uri> founds = Sets.newHashSet(collection.find(Filters.in("_id", uris)) .projection(Projections.include("_id")).map(doc -> Uri.create(doc.getString("_id"))).iterator()); temp.removeAll(founds);// w ww .j a v a 2 s .c om return temp; }
From source file:module.ExportGeo.java
License:Open Source License
public ExportGeo() { String gseNumber = "GSE2109"; // ===== Connection ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collection = db.getCollection("samples"); // ===== Find exp_group in the database ===== List<Document> docExpGroup = collection.find(Filters.in("series", gseNumber)) .projection(Projections.fields(Projections.include("exp_group"), Projections.excludeId())) .into(new ArrayList<Document>()); List<Document> docParam = collection.find(Filters.in("series", gseNumber)) .projection(Projections.fields(Projections.include("parameters"), Projections.excludeId())) .into(new ArrayList<Document>()); mongoClient.close();/* w ww. j a v a 2 s.c o m*/ // ===== Load Exp Group into a matrix ===== List<String> headerExpGroup = new ArrayList<String>(); List<Object> dataExpGroup = new ArrayList<Object>(); for (int i = 0; i < docExpGroup.size(); i++) { Map<String, String> expGroup = (Map<String, String>) docExpGroup.get(i).get("exp_group"); if (i == 0) { headerExpGroup.addAll(expGroup.keySet()); } String[] dataLine = new String[headerExpGroup.size()]; for (int j = 0; j < headerExpGroup.size(); j++) { dataLine[j] = expGroup.get(headerExpGroup.get(j)); } dataExpGroup.add(dataLine); } // ===== Load Params into a matrix ===== Set<String> headerParamSet = new HashSet<String>(); List<String> headerParam = new ArrayList<String>(); List<Object> dataParam = new ArrayList<Object>(); for (int i = 0; i < docParam.size(); i++) { Map<String, String> param = (Map<String, String>) docParam.get(i).get("parameters"); headerParamSet.addAll(param.keySet()); } headerParam.addAll(headerParamSet); Collections.sort(headerParam); for (int i = 0; i < docParam.size(); i++) { Map<String, String> param = (Map<String, String>) docParam.get(i).get("parameters"); String[] dataLine = new String[headerParam.size()]; for (int j = 0; j < headerParam.size(); j++) { dataLine[j] = param.get(headerParam.get(j)); } // System.out.println(Arrays.toString(dataLine)); dataParam.add(dataLine); } // === Output === String fileName = this.getOutputDirectory() + this.getDirSeparator() + "Export_Mongo_" + gseNumber + "_" + dateFormat.format(new Date()) + ".xlsx"; System.out.println(fileName); XSSFWorkbook workbook = fileService.createWorkbook(); fileService.addSheet(workbook, "exp_group" + dateFormat.format(new Date()), headerExpGroup, dataExpGroup); fileService.addSheet(workbook, "parameters_" + dateFormat.format(new Date()), headerParam, dataParam); fileService.writeWorkbook(workbook, fileName); }