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 @Deprecated public Query<T> disableSnapshotMode() { getOptions().getModifiers().removeField("$snapshot"); return this; }
public static DBObject applyExcludeFields(DBObject bsonObject, Set<String> excludeFields) { if (excludeFields == null) { return bsonObject; } DBObject filteredObject = bsonObject; for (String field : excludeFields) { if (field.contains(".")) { String rootObject = field.substring(0, field.indexOf(".")); String childObject = field.substring(field.indexOf(".") + 1); if (filteredObject.containsField(rootObject)) { Object object = filteredObject.get(rootObject); if (object instanceof DBObject) { DBObject object2 = (DBObject) object; object2 = applyExcludeFields(object2, new HashSet<String>(Arrays.asList(childObject))); } } } else { if (filteredObject.containsField(field)) { filteredObject.removeField(field); } } } return filteredObject; }
@Override public <T> T getByKey(final Class<T> clazz, final Key<T> key) { final String collectionName = mapper.getCollectionName(clazz); final String keyCollection = mapper.updateCollection(key); if (!collectionName.equals(keyCollection)) { throw new RuntimeException("collection names don't match for key and class: " + collectionName + " != " + keyCollection); } Object id = key.getId(); if (id instanceof DBObject) { ((DBObject) id).removeField(mapper.getOptions().getDiscriminatorField()); } return get(clazz, id); }
@SuppressWarnings("unchecked") private void flattenOps(DBObject entry) { Object ref = entry.removeField(MongoDBRiver.OPLOG_REF); Object ops = ref == null ? entry.removeField(MongoDBRiver.OPLOG_OPS) : getRefOps(ref); if (ops != null) { try { for (DBObject op : (List<DBObject>) ops) { String operation = (String) op.get(MongoDBRiver.OPLOG_OPERATION); if (operation.equals(MongoDBRiver.OPLOG_COMMAND_OPERATION)) { DBObject object = (DBObject) op.get(MongoDBRiver.OPLOG_OBJECT); if (object.containsField(MongoDBRiver.OPLOG_CREATE_COMMAND)) { continue; } } entry.putAll(op); } } catch (ClassCastException e) { logger.error(e.toString(), e); } } }
final DBObject dbObj = toDBObject(newObj); if (!includeClassName) { dbObj.removeField(opts.getDiscriminatorField());
((DBObject) val).removeField(mapper.getOptions().getDiscriminatorField());
List<DBObject> list = (List<DBObject>) val; for (DBObject o : list) { o.removeField(mapper.getOptions().getDiscriminatorField()); ((DBObject) val).removeField(mapper.getOptions().getDiscriminatorField());
dbObj.removeField("_id");
@Override public void toDBObject(final Object entity, final MappedField mf, final DBObject dbObject, final Map<Object, DBObject> involvedObjects, final Mapper mapper) { final String name = mf.getNameToStore(); final Object fieldValue = mf.getFieldValue(entity); if (mf.isMap()) { writeMap(mf, dbObject, involvedObjects, name, fieldValue, mapper); } else if (mf.isMultipleValues()) { writeCollection(mf, dbObject, involvedObjects, name, fieldValue, mapper); } else { //run converters if (mapper.getConverters().hasDbObjectConverter(mf) || mapper.getConverters().hasDbObjectConverter(entity.getClass())) { mapper.getConverters().toDBObject(entity, mf, dbObject, mapper.getOptions()); return; } final DBObject dbObj = fieldValue == null ? null : mapper.toDBObject(fieldValue, involvedObjects); if (dbObj != null) { if (!shouldSaveClassName(fieldValue, dbObj, mf)) { dbObj.removeField(mapper.getOptions().getDiscriminatorField()); } if (!dbObj.keySet().isEmpty() || mapper.getOptions().isStoreEmpties()) { dbObject.put(name, dbObj); } } } }
for (Object o : list) { if (o instanceof DBObject) { ((DBObject) o).removeField(opts.getDiscriminatorField()); ((DBObject) mappedValue).removeField(opts.getDiscriminatorField());
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())); }
((DBObject) id).removeField(mapper.getOptions().getDiscriminatorField());
private List extractAggregationValues(Iterable<DBObject> documents, BasicDBObject aggregation) { List results = new LinkedList(); if (aggregation != null) { if (aggregation.containsField("_id") && aggregation.get("_id") == null) { aggregation.removeField("_id"); } } for (DBObject document : documents) { if (document.containsField("_id") && document.get("_id") == null) { document.removeField("_id"); } extractAggregationValues(document, results, aggregation != null ? aggregation : (BasicDBObject) document); } return results; }
@Override public void flush() { for (final Iterator<Object> it = value.list.iterator(); it.hasNext(); ) { if (it.next() == null) { it.remove(); } } if (value.list.isEmpty()) { value.parent.removeField(value.fieldName); } }
@Override @Deprecated public Query<T> disableSnapshotMode() { getOptions().getModifiers().removeField("$snapshot"); return this; }
private Object getAttributeValue(YAttribute attribute){ if(attribute.getAttributes() == null || attribute.getAttributes().isEmpty()){ YRichText richText = attribute.getRichValue(); Object richTextObject = converter.convertToMongoType(richText); return richTextObject; } else { DBObject attributeValue = (DBObject) converter.convertToMongoType(attribute, ClassTypeInformation.from(attribute.getClass())); attributeValue.removeField("key"); return attributeValue; } }
public void archiveGridFsFiles(List<GridFSDBFile> gridFsFiles) { for (GridFSDBFile gridFsFile : gridFsFiles) { gridFsFile.getMetaData().removeField(ContentFile.ARCHIVED); gridFsFile.getMetaData().put(ContentFile.ARCHIVED, true); gridFsFile.save(); } }
private DBObject buildReplaceRootUpdate(int currentVersion, Date createTime) { // add query version in case somebody make changes between get and update DBObject rootUpdateObject = entity.getNode(); rootUpdateObject.put(InternalFieldEnum.VERSION.getDbName(), currentVersion + 1); rootUpdateObject.put(InternalFieldEnum.CREATETIME.getDbName(), createTime); rootUpdateObject.put(InternalFieldEnum.STATUS.getDbName(), StatusEnum.ACTIVE.toString()); // remove _id for sub branch rootUpdateObject.removeField("_id"); return rootUpdateObject; } }
@Override public boolean upsert(ID id, E data) { Object idObject = mongoOperations.getConverter().convertToMongoType(id); DBObject dbObject = getDbObject(data); dbObject.removeField("_id"); Update update = new Update(); setField("", dbObject, update); return mongoOperations.upsert(Query.query(Criteria.where("_id").is(idObject)), update, metadata.getCollectionName()).isUpdateOfExisting(); }