case ARRAY: BsonType valueType = keyvalueforStruct.getValue().asArray().get(0).getBsonType(); List<BsonValue> arrValues = keyvalueforStruct.getValue().asArray().getValues(); ArrayList<Object> list = new ArrayList<>();
final String JSON_DATA = "[{\"objA\":{\"foo\":1}}," + "{\"objB\":{\"bar\":2}}]"; final CodecRegistry codecRegistry = CodecRegistries.fromProviders(asList(new ValueCodecProvider(), new BsonValueCodecProvider(), new DocumentCodecProvider())); JsonReader reader = new JsonReader(JSON_DATA); BsonArrayCodec arrayReader = new BsonArrayCodec(codecRegistry); BsonArray docArray = arrayReader.decode(reader, DecoderContext.builder().build()); for (BsonValue doc : docArray.getValues()) { System.out.println(doc); }
@Override public PVector<V> applyUnsafe(BsonValue p) throws BsonInvalidOperationException { BsonArray bsonArray = p.asArray(); List<V> values = bsonArray.getValues().stream().map(v -> itemDeserialiser.apply(v)).collect(Collectors.toList()); return TreePVector.from(values); } }
for(BsonValue v : values.getValues()) { if(v != null && v.isDocument()) { doProjection(key,(BsonDocument)v);
for(BsonValue v : values.getValues()) { if(v != null && v.isDocument()) { doProjection(key,(BsonDocument)v);
children.getValues().stream() .forEach((child) -> { t.transform(
for(BsonValue v : values.getValues()) { if(v != null && v.isDocument()) { doProjection(otherParts,(BsonDocument)v);
for(BsonValue v : values.getValues()) { if(v != null && v.isDocument()) { doProjection(otherParts,(BsonDocument)v);
BsonArray arrayContent = content.asArray(); Iterator<BsonValue> objs = arrayContent.getValues().iterator();
public static List<RequestTransformer> getFromJson(BsonDocument props) throws InvalidMetadataException { BsonValue _rts = props.get(RTS_ELEMENT_NAME); if (_rts == null || !_rts.isArray()) { throw new InvalidMetadataException((_rts == null ? "missing '" : "invalid '") + RTS_ELEMENT_NAME + "' element; it must be an array"); } BsonArray rts = _rts.asArray(); List<RequestTransformer> ret = new ArrayList<>(); for (BsonValue o : rts.getValues()) { if (o.isDocument()) { ret.add(getSingleFromJson(o.asDocument())); } else { throw new InvalidMetadataException("invalid '" + RTS_ELEMENT_NAME + "'. Array elements must be json objects"); } } return ret; }
/** * checks if the aggregation variable start with $ this is not allowed since * the client would be able to modify the aggregation stages * * @param aVars RequestContext.getAggregationVars() */ public static void checkAggregationVariables(BsonValue aVars) throws SecurityException { if (aVars == null) { return; } if (aVars.isDocument()) { BsonDocument _obj = aVars.asDocument(); _obj.forEach((key, value) -> { if (key.startsWith("$")) { throw new SecurityException( "aggregation variables cannot include operators"); } if (value.isDocument() || value.isArray()) { checkAggregationVariables(value); } }); } else if (aVars.isArray()) { aVars.asArray().getValues().stream() .filter(el -> (el.isDocument() || el.isArray())) .forEachOrdered(AbstractAggregationOperation::checkAggregationVariables); } }
Map m = new HashMap<>(); m.put("list", new ArrayList(((BsonArray) value).getValues())); value = convertBSON(m).get("list"); } else //noinspection ConstantConditions
public static List<RequestChecker> getFromJson(BsonDocument props) throws InvalidMetadataException { BsonValue _scs = getProps(props); if (_scs == null || !_scs.isArray()) { throw new InvalidMetadataException( (_scs == null ? "missing '" : "invalid '") + ROOT_KEY + "' element. it must be a json array"); } BsonArray scs = _scs.asArray(); List<RequestChecker> ret = new ArrayList<>(); for (BsonValue o : scs.getValues()) { if (o.isDocument()) { ret.add(getSingleFromJson(o.asDocument())); } else { throw new InvalidMetadataException( "invalid '" + ROOT_KEY + "'. Array elements must be json objects"); } } return ret; }
for (BsonValue _rel : rels.getValues()) { if (!_rel.isDocument()) { throw new InvalidMetadataException(
for (BsonValue _query : aggregations.getValues()) { if (!_query.isDocument()) { throw new InvalidMetadataException("element '"
List<BsonValue> __roles = _roles.asArray().getValues();
List<BsonValue> bsonVals = _referenceValue.asArray().getValues(); BsonValue[] ids = bsonVals.toArray(new BsonValue[bsonVals.size()]);
for (BsonValue doc : docArray.getValues()) { fongo .getDatabase(BALEEN)
BsonArray ret = new BsonArray(); for (BsonValue el : obj.asArray().getValues()) { if (el.isDocument()) { ret.add(bindAggregationVariables(el, aVars));