@Override public boolean pre() { Document index = new Document(StageDocumentToVariantConverter.STUDY_FILE_FIELD, 1); // index.put(ID_FIELD, 1); collection.createIndex(index, new ObjectMap(MongoDBCollection.BACKGROUND, true)); return true; }
private void createIndexes(MongoDBCollection mongoCollection, List<Map<String, ObjectMap>> indexes) { QueryResult<Document> index = mongoCollection.getIndex(); // We store the existing indexes Set<String> existingIndexes = index.getResult() .stream() .map(document -> (String) document.get("name")) .collect(Collectors.toSet()); if (index.getNumResults() != indexes.size() + 1) { // It is + 1 because mongo always create the _id index by default for (Map<String, ObjectMap> userIndex : indexes) { String indexName = ""; Document keys = new Document(); Iterator fieldsIterator = userIndex.get("fields").entrySet().iterator(); while (fieldsIterator.hasNext()) { Map.Entry pair = (Map.Entry) fieldsIterator.next(); keys.append((String) pair.getKey(), pair.getValue()); if (!indexName.isEmpty()) { indexName += "_"; } indexName += pair.getKey() + "_" + pair.getValue(); } if (!existingIndexes.contains(indexName)) { mongoCollection.createIndex(keys, new ObjectMap(userIndex.get("options"))); } } } }
variantsCollection.createIndex(new Document(DocumentToVariantConverter.AT_FIELD + '.' + DocumentToVariantConverter.CHUNK_IDS_FIELD, 1), onBackground); variantsCollection.createIndex(new Document(DocumentToVariantConverter.CHROMOSOME_FIELD, 1) .append(DocumentToVariantConverter.START_FIELD, 1) .append(DocumentToVariantConverter.END_FIELD, 1), onBackground); variantsCollection.createIndex(new Document(DocumentToVariantConverter.IDS_FIELD, 1), onBackground); variantsCollection.createIndex( new Document(DocumentToVariantConverter.STUDIES_FIELD + '.' + STUDYID_FIELD, 1), onBackground); variantsCollection.createIndex( new Document(DocumentToVariantConverter.STUDIES_FIELD + '.' + FILES_FIELD + '.' + FILEID_FIELD, 1), onBackground); variantsCollection.createIndex(new Document(DocumentToVariantConverter.STATS_FIELD + '.' + DocumentToVariantStatsConverter .MAF_FIELD, 1), onBackground); variantsCollection.createIndex(new Document(DocumentToVariantConverter.STATS_FIELD + '.' + DocumentToVariantStatsConverter .MGF_FIELD, 1), onBackground); variantsCollection.createIndex(new Document() .append(DocumentToVariantConverter.ANNOTATION_FIELD + '.' + DocumentToVariantAnnotationConverter.XREFS_FIELD variantsCollection.createIndex(new Document() .append(DocumentToVariantConverter.ANNOTATION_FIELD + '.' + DocumentToVariantAnnotationConverter.CONSEQUENCE_TYPE_FIELD variantsCollection.createIndex(new Document() .append(DocumentToVariantConverter.ANNOTATION_FIELD + '.' + DocumentToVariantAnnotationConverter.GENE_SO_FIELD, 1), onBackgroundSparse);
public MongoDBStudyConfigurationDBAdaptor(MongoDataStore db, String collectionName) { collection = db.getCollection(collectionName) .withReadPreference(ReadPreference.primary()) .withWriteConcern(WriteConcern.ACKNOWLEDGED); collection.createIndex(new Document("studyName", 1), new ObjectMap(MongoDBCollection.UNIQUE, true)); mongoLock = new MongoLock(collection, "_lock"); }
trashCollection.createIndex(new Document(DocumentToTrashVariantConverter.TIMESTAMP_FIELD, 1), new ObjectMap());