@Override void modifyField(Document doc, String field) { doc.remove(field); }
@Override void modifyFieldWithDotNotation(Document doc, String field) { doc.remove(field); }
private Geo2dSphereCriteria manageOption(final String key, final Object value) { if (options == null) { options = new Document(); } if(value == null) { options.remove(key); } else { options.put(key, value); } return this; }
private static void removeFromMap(Bson bson, String key) { if (bson instanceof Document) { ((Document) bson).remove(key); return; } if (bson instanceof DBObject) { ((DBObject) bson).removeField(key); return; } throw new IllegalArgumentException( String.format("Cannot remove from %s. Given Bson must be a Document or DBObject.", bson.getClass())); }
@Override void modifyFieldWithDotNotation(Document doc, String field) { doc.put(checkFieldExists(doc, newField), doc.remove(field)); }
@Override void modifyField(Document doc, String field) { doc.put(checkFieldExists(doc, newFieldNode), doc.remove(field)); }
private void removeConfigPath() { final FindIterable<Document> documentsWithConfigPath = collection.find(exists("configuration_path")); for (Document document : documentsWithConfigPath) { final ObjectId objectId = document.getObjectId("_id"); document.remove("configuration_path"); final UpdateResult updateResult = collection.replaceOne(eq("_id", objectId), document); if (updateResult.wasAcknowledged()) { LOG.debug("Successfully updated document with ID <{}>", objectId); } else { LOG.error("Failed to update document with ID <{}>", objectId); } } }
@Override public MappedDocument toMappedDocument(MongoWriter<? super T> writer) { T bean = propertyAccessor.getBean(); Document document = new Document(); writer.write(bean, document); if (document.containsKey(ID_FIELD) && document.get(ID_FIELD) == null) { document.remove(ID_FIELD); } return MappedDocument.of(document); }
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { if (dbId != null) { collection.replaceOne(Filters.eq("_id", dbId.get("_id")), dbDoc); } else { if (dbDoc.containsKey("_id") && dbDoc.get("_id") == null) { dbDoc.remove("_id"); } collection.insertOne(dbDoc); } return null; } });
document.remove(keyToRemove);
/** * Returns the given {@link Example} as {@link Document} holding matching values extracted from * {@link Example#getProbe()}. * * @param example must not be {@literal null}. * @param entity must not be {@literal null}. * @return */ public Document getMappedExample(Example<?> example, MongoPersistentEntity<?> entity) { Assert.notNull(example, "Example must not be null!"); Assert.notNull(entity, "MongoPersistentEntity must not be null!"); Document reference = (Document) converter.convertToMongoType(example.getProbe()); if (entity.getIdProperty() != null && ClassUtils.isAssignable(entity.getType(), example.getProbeType())) { Object identifier = entity.getIdentifierAccessor(example.getProbe()).getIdentifier(); if (identifier == null) { reference.remove(entity.getIdProperty().getFieldName()); } } ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher()); applyPropertySpecs("", reference, example.getProbeType(), matcherAccessor); Document flattened = ObjectUtils.nullSafeEquals(NullHandler.INCLUDE, matcherAccessor.getNullHandler()) ? reference : new Document(SerializationUtils.flattenMap(reference)); Document result = example.getMatcher().isAllMatching() ? flattened : orConcatenate(flattened); return updateTypeRestrictions(result, example); }
private static void removeFromMap(Bson bson, String key) { if (bson instanceof Document) { ((Document) bson).remove(key); return; } if (bson instanceof DBObject) { ((DBObject) bson).removeField(key); return; } throw new IllegalArgumentException( String.format("Cannot remove from %s. Given Bson must be a Document or DBObject.", bson.getClass())); }
@Override public MappedDocument toMappedDocument(MongoWriter<? super T> writer) { T bean = propertyAccessor.getBean(); Document document = new Document(); writer.write(bean, document); if (document.containsKey(ID_FIELD) && document.get(ID_FIELD) == null) { document.remove(ID_FIELD); } return MappedDocument.of(document); }
document.remove(keyToRemove);
/** * Returns the given {@link Example} as {@link Document} holding matching values extracted from * {@link Example#getProbe()}. * * @param example must not be {@literal null}. * @param entity must not be {@literal null}. * @return */ public Document getMappedExample(Example<?> example, MongoPersistentEntity<?> entity) { Assert.notNull(example, "Example must not be null!"); Assert.notNull(entity, "MongoPersistentEntity must not be null!"); Document reference = (Document) converter.convertToMongoType(example.getProbe()); if (entity.getIdProperty() != null && ClassUtils.isAssignable(entity.getType(), example.getProbeType())) { Object identifier = entity.getIdentifierAccessor(example.getProbe()).getIdentifier(); if (identifier == null) { reference.remove(entity.getIdProperty().getFieldName()); } } ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher()); applyPropertySpecs("", reference, example.getProbeType(), matcherAccessor); Document flattened = ObjectUtils.nullSafeEquals(NullHandler.INCLUDE, matcherAccessor.getNullHandler()) ? reference : new Document(SerializationUtils.flattenMap(reference)); Document result = example.getMatcher().isAllMatching() ? flattened : orConcatenate(flattened); return updateTypeRestrictions(result, example); }
private static MongoDBIndexType determineIndexType(Document options) { MongoDBIndexType indexType = MongoDBIndexType.from( options.getString( INDEX_TYPE_OPTION ) ); options.remove( INDEX_TYPE_OPTION ); // legacy method for setting the text index type if ( MongoDBIndexType.NORMAL.equals( indexType ) && Boolean.TRUE.equals( options.get( "text" ) ) ) { options.remove( "text" ); return MongoDBIndexType.TEXT; } return indexType; }
private Document replaceInMapKeys(Document map, String regexFrom, String from, String to) { for (String key : map.keySet()){ if (key.contains(from)){ String escaped = key.replaceAll(regexFrom, to); Object val = map.get(key); map.remove(key); map.put(escaped, val); } } return map; } }
@Test public void testConvertToDataModelTypeWithoutAF() { DocumentToVariantStatsConverter converter = new DocumentToVariantStatsConverter(); mongoStats.remove(DocumentToVariantStatsConverter.ALT_FREQ_FIELD); mongoStats.remove(DocumentToVariantStatsConverter.REF_FREQ_FIELD); VariantStats converted = converter.convertToDataModelType(mongoStats); assertEquals(stats, converted); }
@Test public void testUpsertFieldOrder() throws Exception { collection.updateOne(json("'x.y': 2"), json("$inc: {a: 7}"), new UpdateOptions().upsert(true)); Document obj = collection.find().first(); obj.remove("_id"); // this actually differs from the official MongoDB implementation assertThat(obj).isEqualTo(json("x: {y: 2}, a: 7")); }
@Override public Document convertToStorageType(Cohort object, List<VariableSet> variableSetList) { Document document = super.convertToStorageType(object, variableSetList); document.remove(CohortDBAdaptor.QueryParams.ANNOTATION_SETS.key()); document.put("uid", object.getUid()); document.put("studyUid", object.getStudyUid()); document.put("samples", convertSamplesToDocument(object.getSamples())); return document; }