本文整理汇总了C++中BSONElement::Array方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::Array方法的具体用法?C++ BSONElement::Array怎么用?C++ BSONElement::Array使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::Array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecordId
void BSONCollectionCatalogEntry::MetaData::parse(const BSONObj& obj) {
ns = obj["ns"].valuestrsafe();
if (obj["options"].isABSONObj()) {
options.parse(obj["options"].Obj());
}
BSONElement e = obj["indexes"];
if (e.isABSONObj()) {
std::vector<BSONElement> entries = e.Array();
for (unsigned i = 0; i < entries.size(); i++) {
BSONObj idx = entries[i].Obj();
IndexMetaData imd;
imd.spec = idx["spec"].Obj().getOwned();
imd.ready = idx["ready"].trueValue();
if (idx.hasField("head")) {
imd.head = RecordId(idx["head"].Long());
} else {
imd.head = RecordId(idx["head_a"].Int(), idx["head_b"].Int());
}
imd.multikey = idx["multikey"].trueValue();
indexes.push_back(imd);
}
}
}
示例2: isGeoJSONPolygon
bool GeoParser::isGeoJSONPolygon(const BSONObj& obj) {
BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
if (type.eoo() || (String != type.type())) { return false; }
if (GEOJSON_TYPE_POLYGON != type.String()) { return false; }
if (!crsIsOK(obj)) {
warning() << "Invalid CRS: " << obj.toString() << endl;
return false;
}
BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
if (coordElt.eoo() || (Array != coordElt.type())) { return false; }
const vector<BSONElement>& coordinates = coordElt.Array();
// Must be at least one element, the outer shell
if (coordinates.empty()) { return false; }
// Verify that the shell is a bunch'a coordinates.
for (size_t i = 0; i < coordinates.size(); ++i) {
if (Array != coordinates[i].type()) { return false; }
const vector<BSONElement>& thisLoop = coordinates[i].Array();
// A triangle is the simplest 2d shape, and we repeat a vertex, so, 4.
if (thisLoop.size() < 4) { return false; }
if (!isArrayOfCoordinates(thisLoop)) { return false; }
if (!isLoopClosed(thisLoop)) { return false; }
}
return true;
}
示例3: parseElementRecursive
virtual void parseElementRecursive(const BSONElement& element, string& key, int elementIndex=0, int elementCount=1, int arrayIndex = -1, int arrayCount = 0) {
BSONType btype = element.type();
switch (btype) {
case BSONType::Object:
{
const BSONObj& bobj = element.Obj();
string k(element.fieldName());
parseObjectRecursive(bobj, k, elementIndex, elementCount, arrayIndex, arrayCount);
}
break;
case BSONType::Array:
{
stack.push(BSONParserStackItem::ItemType::ARRAY, element, key, elementIndex, elementCount, arrayIndex, arrayCount);
std::vector<BSONElement> elementArray = element.Array();
int elementArrayCount = elementArray.size();
visitor.onArrayStart(stack);
int elementArrayIndex = 0;
for (BSONElement e : elementArray) {
string k(e.fieldName());
parseElementRecursive(e, k, elementIndex, elementCount, elementArrayIndex++, elementArrayCount);
}
visitor.onArrayEnd(stack);
stack.drop();
}
break;
default:
{
stack.push(BSONParserStackItem::ItemType::ELEMENT, element, key, elementIndex, elementCount, arrayIndex, arrayCount);
visitor.onElement(stack);
stack.drop();
}
break;
}
}
示例4: parseGeometryCollection
// { "type": "GeometryCollection",
// "geometries": [
// { "type": "Point",
// "coordinates": [100.0, 0.0]
// },
// { "type": "LineString",
// "coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
// }
// ]
// }
Status GeoParser::parseGeometryCollection(const BSONObj& obj,
bool skipValidation,
GeometryCollection* out) {
BSONElement coordElt = obj.getFieldDotted(GEOJSON_GEOMETRIES);
if (Array != coordElt.type())
return BAD_VALUE("GeometryCollection geometries must be an array");
const vector<BSONElement>& geometries = coordElt.Array();
if (0 == geometries.size())
return BAD_VALUE("GeometryCollection geometries must have at least 1 element");
for (size_t i = 0; i < geometries.size(); ++i) {
if (Object != geometries[i].type())
return BAD_VALUE("Element " << i << " of \"geometries\" is not an object");
const BSONObj& geoObj = geometries[i].Obj();
GeoJSONType type = parseGeoJSONType(geoObj);
if (GEOJSON_UNKNOWN == type)
return BAD_VALUE("Unknown GeoJSON type: " << geometries[i].toString(false));
if (GEOJSON_GEOMETRY_COLLECTION == type)
return BAD_VALUE(
"GeometryCollections cannot be nested: " << geometries[i].toString(false));
Status status = Status::OK();
if (GEOJSON_POINT == type) {
out->points.resize(out->points.size() + 1);
status = parseGeoJSONPoint(geoObj, &out->points.back());
} else if (GEOJSON_LINESTRING == type) {
out->lines.mutableVector().push_back(new LineWithCRS());
status = parseGeoJSONLine(geoObj, skipValidation, out->lines.vector().back());
} else if (GEOJSON_POLYGON == type) {
out->polygons.mutableVector().push_back(new PolygonWithCRS());
status = parseGeoJSONPolygon(geoObj, skipValidation, out->polygons.vector().back());
} else if (GEOJSON_MULTI_POINT == type) {
out->multiPoints.mutableVector().push_back(new MultiPointWithCRS());
status = parseMultiPoint(geoObj, out->multiPoints.mutableVector().back());
} else if (GEOJSON_MULTI_LINESTRING == type) {
out->multiLines.mutableVector().push_back(new MultiLineWithCRS());
status = parseMultiLine(geoObj, skipValidation, out->multiLines.mutableVector().back());
} else if (GEOJSON_MULTI_POLYGON == type) {
out->multiPolygons.mutableVector().push_back(new MultiPolygonWithCRS());
status = parseMultiPolygon(
geoObj, skipValidation, out->multiPolygons.mutableVector().back());
} else {
// Should not reach here.
invariant(false);
}
// Check parsing result.
if (!status.isOK())
return status;
}
return Status::OK();
}
示例5: set
// static
Status SetFilter::set(OperationContext* opCtx,
QuerySettings* querySettings,
PlanCache* planCache,
const string& ns,
const BSONObj& cmdObj) {
// indexes - required
BSONElement indexesElt = cmdObj.getField("indexes");
if (indexesElt.eoo()) {
return Status(ErrorCodes::BadValue, "required field indexes missing");
}
if (indexesElt.type() != mongo::Array) {
return Status(ErrorCodes::BadValue, "required field indexes must be an array");
}
vector<BSONElement> indexesEltArray = indexesElt.Array();
if (indexesEltArray.empty()) {
return Status(ErrorCodes::BadValue,
"required field indexes must contain at least one index");
}
BSONObjSet indexes = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
stdx::unordered_set<std::string> indexNames;
for (vector<BSONElement>::const_iterator i = indexesEltArray.begin();
i != indexesEltArray.end();
++i) {
const BSONElement& elt = *i;
if (elt.type() == BSONType::Object) {
BSONObj obj = elt.Obj();
if (obj.isEmpty()) {
return Status(ErrorCodes::BadValue, "index specification cannot be empty");
}
indexes.insert(obj.getOwned());
} else if (elt.type() == BSONType::String) {
indexNames.insert(elt.String());
} else {
return Status(ErrorCodes::BadValue, "each item in indexes must be an object or string");
}
}
auto statusWithCQ = PlanCacheCommand::canonicalize(opCtx, ns, cmdObj);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
// Add allowed indices to query settings, overriding any previous entries.
querySettings->setAllowedIndices(*cq, planCache->computeKey(*cq), indexes, indexNames);
// Remove entry from plan cache.
planCache->remove(*cq).transitional_ignore();
LOG(0) << "Index filter set on " << ns << " " << redact(cq->toStringShort()) << " "
<< indexesElt;
return Status::OK();
}
示例6: compoundVectorResponse
/* ****************************************************************************
*
* compoundVectorResponse -
*/
void compoundVectorResponse(orion::CompoundValueNode* cvP, const BSONElement& be)
{
std::vector<BSONElement> vec = be.Array();
cvP->valueType = orion::ValueTypeVector;
for (unsigned int ix = 0; ix < vec.size(); ++ix)
{
BSONElement e = vec[ix];
addCompoundNode(cvP, e);
}
}
示例7: GetArrayFieldValue
bool CMongodbModel::GetArrayFieldValue(const BSONObj& boInfo,
string strFieldName,
std::vector<BSONElement>& vtValue)
{
bool bResult = false;
if (boInfo.hasField(strFieldName))
{
BSONElement beInfo = boInfo[strFieldName];
vtValue = beInfo.Array();
bResult = true;
}
return bResult;
}
示例8: parseMultiPoint
bool GeoParser::parseMultiPoint(const BSONObj &obj, MultiPointWithCRS *out) {
out->points.clear();
BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
const vector<BSONElement>& coordinates = coordElt.Array();
out->points.resize(coordinates.size());
out->cells.resize(coordinates.size());
for (size_t i = 0; i < coordinates.size(); ++i) {
const vector<BSONElement>& thisCoord = coordinates[i].Array();
out->points[i] = coordToPoint(thisCoord[0].Number(), thisCoord[1].Number());
out->cells[i] = S2Cell(out->points[i]);
}
return true;
}
示例9: checkAuthForApplyOpsCommand
Status checkAuthForApplyOpsCommand(OperationContext* txn,
const std::string& dbname,
const BSONObj& cmdObj) {
AuthorizationSession* authSession = AuthorizationSession::get(txn->getClient());
ApplyOpsValidity validity = validateApplyOpsCommand(cmdObj);
if (validity == ApplyOpsValidity::kNeedsSuperuser) {
std::vector<Privilege> universalPrivileges;
RoleGraph::generateUniversalPrivileges(&universalPrivileges);
if (!authSession->isAuthorizedForPrivileges(universalPrivileges)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized");
}
return Status::OK();
}
fassert(40314, validity == ApplyOpsValidity::kOk);
boost::optional<DisableDocumentValidation> maybeDisableValidation;
if (shouldBypassDocumentValidationForCommand(cmdObj))
maybeDisableValidation.emplace(txn);
const bool alwaysUpsert =
cmdObj.hasField("alwaysUpsert") ? cmdObj["alwaysUpsert"].trueValue() : true;
checkBSONType(BSONType::Array, cmdObj.firstElement());
for (const BSONElement& e : cmdObj.firstElement().Array()) {
checkBSONType(BSONType::Object, e);
Status status = checkOperationAuthorization(txn, dbname, e.Obj(), alwaysUpsert);
if (!status.isOK()) {
return status;
}
}
BSONElement preconditions = cmdObj["preCondition"];
if (!preconditions.eoo()) {
for (const BSONElement& precondition : preconditions.Array()) {
checkBSONType(BSONType::Object, precondition);
BSONElement nsElem = precondition.Obj()["ns"];
checkBSONType(BSONType::String, nsElem);
NamespaceString nss(nsElem.checkAndGetStringData());
if (!authSession->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(nss), ActionType::find)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized to check precondition");
}
}
}
return Status::OK();
}
示例10: Status
StatusWith<std::vector<BSONElement>> DatabasesCloner::_parseListDatabasesResponse(
BSONObj dbResponse) {
if (!dbResponse.hasField("databases")) {
return Status(ErrorCodes::BadValue,
"The 'listDatabases' response does not contain a 'databases' field.");
}
BSONElement response = dbResponse["databases"];
try {
return response.Array();
} catch (const AssertionException&) {
return Status(ErrorCodes::BadValue,
"The 'listDatabases' response is unable to be transformed into an array.");
}
}
示例11: set
// static
Status SetFilter::set(OperationContext* txn,
QuerySettings* querySettings,
PlanCache* planCache,
const string& ns,
const BSONObj& cmdObj) {
// indexes - required
BSONElement indexesElt = cmdObj.getField("indexes");
if (indexesElt.eoo()) {
return Status(ErrorCodes::BadValue, "required field indexes missing");
}
if (indexesElt.type() != mongo::Array) {
return Status(ErrorCodes::BadValue, "required field indexes must be an array");
}
vector<BSONElement> indexesEltArray = indexesElt.Array();
if (indexesEltArray.empty()) {
return Status(ErrorCodes::BadValue,
"required field indexes must contain at least one index");
}
vector<BSONObj> indexes;
for (vector<BSONElement>::const_iterator i = indexesEltArray.begin();
i != indexesEltArray.end();
++i) {
const BSONElement& elt = *i;
if (!elt.isABSONObj()) {
return Status(ErrorCodes::BadValue, "each item in indexes must be an object");
}
BSONObj obj = elt.Obj();
if (obj.isEmpty()) {
return Status(ErrorCodes::BadValue, "index specification cannot be empty");
}
indexes.push_back(obj.getOwned());
}
auto statusWithCQ = PlanCacheCommand::canonicalize(txn, ns, cmdObj);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
// Add allowed indices to query settings, overriding any previous entries.
querySettings->setAllowedIndices(*cq, planCache->computeKey(*cq), indexes);
// Remove entry from plan cache.
planCache->remove(*cq);
LOG(0) << "Index filter set on " << ns << " " << cq->toStringShort() << " " << indexesElt;
return Status::OK();
}
示例12: Status
StatusWith<std::vector<BSONElement>> CollectionCloner::_parseParallelCollectionScanResponse(
BSONObj resp) {
if (!resp.hasField("cursors")) {
return Status(ErrorCodes::CursorNotFound,
"The 'parallelCollectionScan' response does not contain a 'cursors' field.");
}
BSONElement response = resp["cursors"];
if (response.type() == BSONType::Array) {
return response.Array();
} else {
return Status(
ErrorCodes::FailedToParse,
"The 'parallelCollectionScan' response is unable to be transformed into an array.");
}
}
示例13: isGeoJSONPolygon
static bool isGeoJSONPolygon(const BSONObj& obj) {
BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
if (type.eoo() || (String != type.type())) { return false; }
if (GEOJSON_TYPE_POLYGON != type.String()) { return false; }
if (!GeoParser::crsIsOK(obj)) {
warning() << "Invalid CRS: " << obj.toString() << endl;
return false;
}
BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
if (coordElt.eoo() || (Array != coordElt.type())) { return false; }
return isGeoJSONPolygonCoordinates(coordElt.Array());
}
示例14: isLine
bool GeoParser::isLine(const BSONObj& obj) {
BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
if (type.eoo() || (String != type.type())) { return false; }
if (GEOJSON_TYPE_LINESTRING != type.String()) { return false; }
if (!crsIsOK(obj)) {
warning() << "Invalid CRS: " << obj.toString() << endl;
return false;
}
BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
if (coordElt.eoo() || (Array != coordElt.type())) { return false; }
return isValidLineString(coordElt.Array());
}
示例15: isGeoJSONLineString
bool GeoParser::isGeoJSONLineString(const BSONObj& obj) {
BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
if (type.eoo() || (String != type.type())) { return false; }
if (GEOJSON_TYPE_LINESTRING != type.String()) { return false; }
if (!crsIsOK(obj)) {
warning() << "Invalid CRS: " << obj.toString() << endl;
return false;
}
BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
if (coordElt.eoo() || (Array != coordElt.type())) { return false; }
const vector<BSONElement>& coordinateArray = coordElt.Array();
if (coordinateArray.size() < 2) { return false; }
return isArrayOfCoordinates(coordinateArray);
}