private BsonArray tagsListToBsonArray() { BsonArray bsonArray = new BsonArray(); for (TagSet tagSet : tagSetList) { bsonArray.add(toDocument(tagSet)); } return bsonArray; }
private void promoteRenderableToDollarForm(final BsonDocument document, final Map.Entry<String, BsonValue> clause) { BsonArray clauses = new BsonArray(); for (Map.Entry<String, BsonValue> queryElement : document.entrySet()) { clauses.add(new BsonDocument(queryElement.getKey(), queryElement.getValue())); } clauses.add(new BsonDocument(clause.getKey(), clause.getValue())); document.clear(); document.put("$and", clauses); }
void add(final BsonValue value) { if (container instanceof BsonArray) { ((BsonArray) container).add(value); } else { ((BsonDocument) container).put(getName(), value); } } }
@Override public BsonArray clone() { BsonArray to = new BsonArray(); for (BsonValue cur : this) { switch (cur.getBsonType()) { case DOCUMENT: to.add(cur.asDocument().clone()); break; case ARRAY: to.add(cur.asArray().clone()); break; case BINARY: to.add(BsonBinary.clone(cur.asBinary())); break; case JAVASCRIPT_WITH_SCOPE: to.add(BsonJavaScriptWithScope.clone(cur.asJavaScriptWithScope())); break; default: to.add(cur); } } return to; } }
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument filterDocument = filter.toBsonDocument(documentClass, codecRegistry); if (filterDocument.size() == 1) { Map.Entry<String, BsonValue> entry = filterDocument.entrySet().iterator().next(); return createFilter(entry.getKey(), entry.getValue()); } else { BsonArray values = new BsonArray(); for (Map.Entry<String, BsonValue> docs : filterDocument.entrySet()) { values.add(new BsonDocument(docs.getKey(), docs.getValue())); } return createFilter("$and", values); } }
@Override public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) { BsonDocument orRenderable = new BsonDocument(); BsonArray filtersArray = new BsonArray(); for (Bson filter : filters) { filtersArray.add(filter.toBsonDocument(documentClass, codecRegistry)); } orRenderable.put(operator.name, filtersArray); return orRenderable; }
private void addClause(final BsonDocument document, final Map.Entry<String, BsonValue> clause) { if (clause.getKey().equals("$and")) { for (BsonValue value : clause.getValue().asArray()) { for (Map.Entry<String, BsonValue> element : value.asDocument().entrySet()) { addClause(document, element); } } } else if (document.size() == 1 && document.keySet().iterator().next().equals("$and")) { document.get("$and").asArray().add(new BsonDocument(clause.getKey(), clause.getValue())); } else if (document.containsKey(clause.getKey())) { if (document.get(clause.getKey()).isDocument() && clause.getValue().isDocument()) { BsonDocument existingClauseValue = document.get(clause.getKey()).asDocument(); BsonDocument clauseValue = clause.getValue().asDocument(); if (keysIntersect(clauseValue, existingClauseValue)) { promoteRenderableToDollarForm(document, clause); } else { existingClauseValue.putAll(clauseValue); } } else { promoteRenderableToDollarForm(document, clause); } } else { document.append(clause.getKey(), clause.getValue()); } }
/** * Creates a filter that matches all documents containing a field with grid coordinates data that exist entirely within the specified * polygon. * * @param fieldName the field name * @param points a list of pairs of x, y coordinates. Any extra dimensions are ignored * @return the filter * @mongodb.driver.manual reference/operator/query/geoWithin/ $geoWithin * @mongodb.driver.manual reference/operator/query/polygon/#op._S_polygon $polygon * @mongodb.server.release 2.4 * @since 3.1 */ public static Bson geoWithinPolygon(final String fieldName, final List<List<Double>> points) { BsonArray pointsArray = new BsonArray(); for (List<Double> point : points) { pointsArray.add(new BsonArray(asList(new BsonDouble(point.get(0)), new BsonDouble(point.get(1))))); } BsonDocument polygon = new BsonDocument("$polygon", pointsArray); return new OperatorFilter<BsonDocument>("$geoWithin", fieldName, polygon); }
private BsonDocument asCommandResponseDocument() { BsonArray cursorIdArray = new BsonArray(); for (long cursorId : cursors) { cursorIdArray.add(new BsonInt64(cursorId)); } return new BsonDocument("ok", new BsonDouble(1)) .append("cursorsUnknown", cursorIdArray); }
private BsonDocument createIsMasterCommand() { BsonDocument isMasterCommandDocument = new BsonDocument("ismaster", new BsonInt32(1)); if (clientMetadataDocument != null) { isMasterCommandDocument.append("client", clientMetadataDocument); } if (!requestedCompressors.isEmpty()) { BsonArray compressors = new BsonArray(); for (MongoCompressor cur : this.requestedCompressors) { compressors.add(new BsonString(cur.getName())); } isMasterCommandDocument.append("compression", compressors); } if (checkSaslSupportedMechs) { MongoCredential credential = authenticators.get(0).getMongoCredential(); isMasterCommandDocument.append("saslSupportedMechs", new BsonString(credential.getSource() + "." + credential.getUserName())); } return isMasterCommandDocument; }
private BsonDocument asCommandDocument() { BsonArray array = new BsonArray(); for (long cursor : cursors) { array.add(new BsonInt64(cursor)); } return new BsonDocument(COMMAND_NAME, namespace == null ? new BsonInt32(1) : new BsonString(namespace.getCollectionName())) .append("cursors", array); }
private void assureJsonArraySize(BsonArray jsonArray, Integer index) { while (index >= jsonArray.size()) { jsonArray.add(BsonNull.VALUE); } }
@Override protected BsonArray toCoordinates() { BsonArray coordinates = new BsonArray(); for ( List<GeoPoint> ring : rings ) { BsonArray ringCoordinates = new BsonArray(); for ( GeoPoint geoPoint : ring ) { ringCoordinates.add( geoPoint.toCoordinates() ); } coordinates.add( ringCoordinates ); } return coordinates; }
@Override protected BsonArray toCoordinates() { BsonArray coordinates = new BsonArray(); for ( GeoPoint geoPoint : points ) { coordinates.add( geoPoint.toCoordinates() ); } return coordinates; }
@Override protected BsonArray toCoordinates() { BsonArray coordinates = new BsonArray(); for ( GeoLineString geoLineString : lineStrings ) { coordinates.add( geoLineString.toCoordinates() ); } return coordinates; }
@Override protected BsonArray toCoordinates() { BsonArray coordinates = new BsonArray(); for ( GeoPolygon geoPolygon : polygons ) { coordinates.add( geoPolygon.toCoordinates() ); } return coordinates; }
/** * * @param rel * @param rep */ public void addRepresentation(String rel, Representation rep) { if (!embedded.containsKey(rel)) { embedded.append(rel, new BsonArray()); } BsonArray repArray = embedded.getArray(rel); repArray.add(rep.asBsonDocument()); }
/** * * @param link * @param inArray */ public void addLink(Link link, boolean inArray) { BsonArray linkArray = addLinkArray(link.getRef()); linkArray.add(link.getBsonDocument().get(link.getRef())); links.put(link.getRef(), linkArray); }
private BsonDocument asCommandDocument() { BsonArray array = new BsonArray(); for (long cursor : cursors) { array.add(new BsonInt64(cursor)); } return new BsonDocument(COMMAND_NAME, namespace == null ? new BsonInt32(1) : new BsonString(namespace.getCollectionName())) .append("cursors", array); }