protected void unmarkPermissionRule(MongoDBCollection collection, long studyId, String permissionRuleId) { Bson query = new Document() .append(PRIVATE_STUDY_ID, studyId) .append(PERMISSION_RULES_APPLIED, permissionRuleId); Bson update = Updates.pull(PERMISSION_RULES_APPLIED, permissionRuleId); collection.update(query, update, new QueryOptions("multi", true)); }
pull(DocumentToVariantConverter.STUDIES_FIELD + ".$." + FILES_FIELD, in(FILEID_FIELD, fileIds))); for (String gt : sc.getAttributes().getAsStringList(LOADED_GENOTYPES.key())) {
private QueryResult<UpdateResult> removeStudyFromVariants(int studyId, Bson query, long timestamp) { // { $pull : { files : { sid : <studyId> } } } Bson update = combine( pull(DocumentToVariantConverter.STUDIES_FIELD, eq(STUDYID_FIELD, studyId)), pull(DocumentToVariantConverter.STATS_FIELD, eq(DocumentToVariantStatsConverter.STUDY_ID, studyId)), getSetIndexNotSynchronized(timestamp) ); logger.debug("removeStudy: query = {}", query.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); logger.debug("removeStudy: update = {}", update.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); QueryResult<UpdateResult> result = variantsCollection.update(query, update, new QueryOptions(MULTI, true)); logger.debug("removeStudy: matched = {}", result.first().getMatchedCount()); logger.debug("removeStudy: modified = {}", result.first().getModifiedCount()); return result; }
private void removeAnnotationSet(long entryId, String annotationSetId, boolean isVersioned) throws CatalogDBException { Document queryDocument = new Document(PRIVATE_UID, entryId); if (isVersioned) { queryDocument.append(LAST_OF_VERSION, true); } Bson pull = Updates.pull(AnnotationSetParams.ANNOTATION_SETS.key(), new Document(AnnotationSetParams.ANNOTATION_SET_NAME.key(), annotationSetId)); QueryResult<UpdateResult> update = getCollection().update(queryDocument, pull, new QueryOptions("multi", true)); if (update.first().getModifiedCount() < 1) { throw new CatalogDBException("Could not delete the annotation set"); } }
)) .append("$isolated", 1); Bson pull = Updates.pull("groups.$.userIds", user);
ids.add(cursor.next().getString("_id")); Bson updateStage = combine( pull(StageDocumentToVariantConverter.STUDY_FILE_FIELD, studyId.toString()), unset(studyId.toString())); if (ids.size() == batchSize || !cursor.hasNext()) {
@Test public void testUpdatePull() throws Exception { Document obj = json("_id: 1"); collection.insertOne(obj); // pull from non-existing field collection.updateOne(obj, json("$pull: {field1: 'value2', field2: 'value3'}")); assertThat(collection.find(obj).first()).isEqualTo(obj); // pull from non-array collection.updateOne(obj, set("field", "value")); assertMongoWriteException(() -> collection.updateOne(obj, pull("field", "value")), 2, "Cannot apply $pull to a non-array value"); // pull standard collection.updateOne(obj, json("$set: {field: ['value1', 'value2', 'value1']}")); collection.updateOne(obj, pull("field", "value1")); assertThat(collection.find(obj).first().get("field")).isEqualTo(Collections.singletonList("value2")); // pull with multiple fields collection.updateOne(obj, json("$set: {field1: ['value1', 'value2', 'value1']}")); collection.updateOne(obj, json("$set: {field2: ['value3', 'value3', 'value1']}")); collection.updateOne(obj, json("$pull: {field1: 'value2', field2: 'value3'}")); assertThat(collection.find(obj).first().get("field1")).isEqualTo(Arrays.asList("value1", "value1")); assertThat(collection.find(obj).first().get("field2")).isEqualTo(Collections.singletonList("value1")); }
Bson combine = combine(pull(StageDocumentToVariantConverter.STUDY_FILE_FIELD, studyId.toString()), unset(studyId.toString())); logger.debug("removeStudy: stage query = " + eq.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); logger.debug("removeStudy: stage update = " + combine.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry()));
@Override public QueryResult deleteFilter(String userId, String name) throws CatalogDBException { long startTime = startQuery(); // Delete the filter Bson bsonQuery = Filters.and( Filters.eq(QueryParams.ID.key(), userId), Filters.eq(QueryParams.CONFIGS_FILTERS_NAME.key(), name) ); Bson update = Updates.pull(QueryParams.CONFIGS_FILTERS.key(), new Document(FilterParams.NAME.key(), name)); QueryResult<UpdateResult> queryResult = userCollection.update(bsonQuery, update, null); if (queryResult.first().getModifiedCount() == 0) { throw new CatalogDBException("Internal error: Filter " + name + " could not be removed"); } return endQuery("Delete filter", startTime, Arrays.asList(queryResult.first().getModifiedCount())); }
@Override public QueryResult<VariableSet> deleteVariableSet(long variableSetId, QueryOptions queryOptions, String user) throws CatalogDBException, CatalogAuthorizationException { long startTime = startQuery(); QueryResult<VariableSet> variableSet = getVariableSet(variableSetId, queryOptions, user); checkVariableSetInUse(variableSetId); Bson query = Filters.eq(QueryParams.VARIABLE_SET_UID.key(), variableSetId); Bson operation = Updates.pull("variableSets", Filters.eq(PRIVATE_UID, variableSetId)); QueryResult<UpdateResult> update = studyCollection.update(query, operation, null); if (update.first().getModifiedCount() == 0) { throw CatalogDBException.uidNotFound("VariableSet", variableSetId); } return endQuery("Delete VariableSet", startTime, variableSet); }
@Override public QueryResult<VariableSet> removeFieldFromVariableSet(long variableSetId, String name, String user) throws CatalogDBException, CatalogAuthorizationException { long startTime = startQuery(); QueryResult<VariableSet> variableSet = getVariableSet(variableSetId, new QueryOptions(), user); checkVariableInVariableSet(variableSet.first(), name); Bson bsonQuery = Filters.eq(QueryParams.VARIABLE_SET_UID.key(), variableSetId); Bson update = Updates.pull(QueryParams.VARIABLE_SET.key() + ".$." + VariableSetParams.VARIABLE.key(), Filters.eq("id", name)); QueryResult<UpdateResult> queryResult = studyCollection.update(bsonQuery, update, null); if (queryResult.first().getModifiedCount() != 1) { throw new CatalogDBException("Remove field from Variable Set. Could not remove the field " + name + " from the variableSet id " + variableSetId); } // Remove all the annotations from that field dbAdaptorFactory.getCatalogSampleDBAdaptor().removeAnnotationField(variableSetId, name); dbAdaptorFactory.getCatalogCohortDBAdaptor().removeAnnotationField(variableSetId, name); dbAdaptorFactory.getCatalogIndividualDBAdaptor().removeAnnotationField(variableSetId, name); dbAdaptorFactory.getCatalogFamilyDBAdaptor().removeAnnotationField(variableSetId, name); dbAdaptorFactory.getCatalogFileDBAdaptor().removeAnnotationField(variableSetId, name); return endQuery("Remove field from Variable Set", startTime, getVariableSet(variableSetId, null)); }