@Override public AggregationPipeline project(final Projection... projections) { firstStage = stages.isEmpty(); DBObject dbObject = new BasicDBObject(); for (Projection projection : projections) { dbObject.putAll(toDBObject(projection)); } stages.add(new BasicDBObject("$project", dbObject)); return this; }
private static void addAllToMap(Bson bson, Map<String, ?> value) { if (bson instanceof Document) { ((Document) bson).putAll(value); return; } if (bson instanceof DBObject) { ((DBObject) bson).putAll(value); return; } throw new IllegalArgumentException( String.format("Cannot add all to %s. Given Bson must be a Document or DBObject.", bson.getClass())); }
@Override public AggregationPipeline group(final List<Group> id, final Group... groupings) { DBObject idGroup = null; if (id != null) { idGroup = new BasicDBObject(); for (Group group : id) { idGroup.putAll(toDBObject(group)); } } DBObject group = new BasicDBObject("_id", idGroup); for (Group grouping : groupings) { group.putAll(toDBObject(grouping)); } stages.add(new BasicDBObject("$group", group)); return this; }
@Override public AggregationPipeline group(final String id, final Group... groupings) { DBObject group = new BasicDBObject(); group.put("_id", id != null ? "$" + id : null); for (Group grouping : groupings) { group.putAll(toDBObject(grouping)); } stages.add(new BasicDBObject("$group", group)); return this; }
@Override @Deprecated public DBObject getQueryObject() { final DBObject obj = new BasicDBObject(); if (baseQuery != null) { obj.putAll(baseQuery.toMap()); } addTo(obj); return obj; }
private void project(final DBObject value) { DBObject projection = getOptions().getProjection(); if (projection == null) { projection = new BasicDBObject(); getOptions().projection(projection); } projection.putAll(value); }
DBObject projections = new BasicDBObject(); for (Projection subProjection : list) { projections.putAll(toDBObject(subProjection));
@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); } } }
@Override public void addTo(final DBObject obj) { BasicDBObjectBuilder query; FilterOperator operator = getOperator(); GeometryQueryConverter geometryQueryConverter = new GeometryQueryConverter(getQuery().getDatastore().getMapper()); final DBObject geometryAsDBObject = (DBObject) geometryQueryConverter.encode(geometry, null); switch (operator) { case NEAR: case NEAR_SPHERE: if (options != null) { geometryAsDBObject.putAll(options); } query = BasicDBObjectBuilder.start(NEAR.val(), geometryAsDBObject); break; case GEO_WITHIN: case INTERSECTS: query = BasicDBObjectBuilder.start(operator.val(), geometryAsDBObject); if (crs != null) { ((DBObject) geometryAsDBObject.get("$geometry")).put("crs", new NamedCoordinateReferenceSystemConverter().encode(crs)); } break; default: throw new UnsupportedOperationException(String.format("Operator %s not supported for geo-query", operator.val())); } obj.put(getField(), query.get()); } }
private static void addAllToMap(Bson bson, Map<String, ?> value) { if (bson instanceof Document) { ((Document) bson).putAll(value); return; } if (bson instanceof DBObject) { ((DBObject) bson).putAll(value); return; } throw new IllegalArgumentException( String.format("Cannot add all to %s. Given Bson must be a Document or DBObject.", bson.getClass())); }
@SuppressWarnings({ "rawtypes" }) @Override public final void putAll(Map m) { documentMap.putAll(m); }
/** * Initialize custom top level elements to appear in a log event * <p> * Allows users to create custom properties to be added to the top level log event. */ public void initTopLevelProperties() { constants = new BasicDBObject(); if (!rootProperties.isEmpty()) { constants.putAll(rootProperties); } }
public DBObject getQueryObject() { DBObject obj = new BasicDBObject(); if (this.baseQuery != null) { obj.putAll((BSONObject) this.baseQuery); } this.addTo(obj); return obj; }
@Override public AggregationPipeline project(final Projection... projections) { firstStage = stages.isEmpty(); DBObject dbObject = new BasicDBObject(); for (Projection projection : projections) { dbObject.putAll(toDBObject(projection)); } stages.add(new BasicDBObject("$project", dbObject)); return this; }
@SuppressWarnings("unchecked") @Override public void endNode() { BSONNode closingElement = itemStack.pop(); if (itemStack.isEmpty()) { // we've popped the last one, so we're done root.putAll(closingElement.asDBObject()); } }
@Override @Deprecated public DBObject getQueryObject() { final DBObject obj = new BasicDBObject(); if (baseQuery != null) { obj.putAll((BSONObject) baseQuery); } addTo(obj); return obj; }
@SuppressWarnings("unchecked") @Override public void endNode() { BSONNode closingElement = itemStack.pop(); if (itemStack.isEmpty()) { // we've popped the last one, so we're done root.putAll(closingElement.asDBObject()); } }
public DBObject getKeys() { BasicDBObjectBuilder keys = new BasicDBObjectBuilder(); for (Map.Entry<String, IndexDirection> entry : filteredFields.entrySet()) { keys.add(entry.getKey(), entry.getValue().toIndexValue()); } DBObject compoundFields = keys.get(); compoundFields.putAll(super.getKeys()); return compoundFields; } }
@Override public V setValue(V value) { V old = getValue(); document.putAll(serializer.toDBObject(value, false, false)); collection.save(document); return old; }
@Override @RequiresServiceRole(roleName = "WRITE") public void addEntry(final Entry entry) { final Map<String, Object> entryMap = entryConverter.convertEntryToMap(entry); final DBObject dbObject = new BasicDBObject(); dbObject.putAll(entryMap); try { accessor.getCollection().insert(dbObject, WriteConcern.ACKNOWLEDGED); } catch (WriteConcernException e) { throw new GeneralServiceException(e, "Error adding new entry to the dictionary, entry: {}, error: {}", entry, e.getErrorCode()); } }