本文整理汇总了C++中BSONElement::embeddedObject方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::embeddedObject方法的具体用法?C++ BSONElement::embeddedObject怎么用?C++ BSONElement::embeddedObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::embeddedObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Status
Status _initializeUserRolesFromV1RolesArray(User* user,
const BSONElement& rolesElement,
const StringData& dbname) {
static const char privilegesTypeMismatchMessage[] =
"Roles in V1 user documents must be enumerated in an array of strings.";
if (rolesElement.type() != Array)
return Status(ErrorCodes::TypeMismatch, privilegesTypeMismatchMessage);
for (BSONObjIterator iter(rolesElement.embeddedObject()); iter.more(); iter.next()) {
BSONElement roleElement = *iter;
if (roleElement.type() != String)
return Status(ErrorCodes::TypeMismatch, privilegesTypeMismatchMessage);
user->addRole(RoleName(roleElement.String(), dbname));
}
return Status::OK();
}
示例2: parseLegacyQuery
bool GeoNearExpression::parseLegacyQuery(const BSONObj& obj) {
bool hasGeometry = false;
// First, try legacy near, e.g.:
// t.find({ loc : { $nearSphere: [0,0], $minDistance: 1, $maxDistance: 3 }})
// t.find({ loc : { $nearSphere: [0,0] }})
// t.find({ loc : { $near : [0, 0, 1] } });
// t.find({ loc : { $near: { someGeoJSONPoint}})
// t.find({ loc : { $geoNear: { someGeoJSONPoint}})
BSONObjIterator it(obj);
while (it.more()) {
BSONElement e = it.next();
if (equals(e.fieldName(), "$near") || equals(e.fieldName(), "$geoNear") ||
equals(e.fieldName(), "$nearSphere")) {
if (!e.isABSONObj()) {
return false;
}
BSONObj embeddedObj = e.embeddedObject();
if (GeoParser::parseQueryPoint(e, centroid.get()).isOK() ||
GeoParser::parsePointWithMaxDistance(embeddedObj, centroid.get(), &maxDistance)) {
uassert(18522, "max distance must be non-negative", maxDistance >= 0.0);
hasGeometry = true;
isNearSphere = equals(e.fieldName(), "$nearSphere");
}
} else if (equals(e.fieldName(), "$minDistance")) {
uassert(16893, "$minDistance must be a number", e.isNumber());
minDistance = e.Number();
uassert(16894, "$minDistance must be non-negative", minDistance >= 0.0);
} else if (equals(e.fieldName(), "$maxDistance")) {
uassert(16895, "$maxDistance must be a number", e.isNumber());
maxDistance = e.Number();
uassert(16896, "$maxDistance must be non-negative", maxDistance >= 0.0);
} else if (equals(e.fieldName(), "$uniqueDocs")) {
warning() << "ignoring deprecated option $uniqueDocs";
} else {
// In a query document, $near queries can have no non-geo sibling parameters.
uasserted(34413,
str::stream() << "invalid argument in geo near query: " << e.fieldName());
}
}
return hasGeometry;
}
示例3: uassert
intrusive_ptr<DocumentSource> DocumentSourceCollStats::createFromBson(
BSONElement specElem, const intrusive_ptr<ExpressionContext>& pExpCtx) {
uassert(40166,
str::stream() << "$collStats must take a nested object but found: " << specElem,
specElem.type() == BSONType::Object);
intrusive_ptr<DocumentSourceCollStats> collStats(new DocumentSourceCollStats(pExpCtx));
for (const auto& elem : specElem.embeddedObject()) {
StringData fieldName = elem.fieldNameStringData();
if ("latencyStats" == fieldName) {
uassert(40167,
str::stream() << "latencyStats argument must be an object, but got " << elem
<< " of type "
<< typeName(elem.type()),
elem.type() == BSONType::Object);
if (!elem["histograms"].eoo()) {
uassert(40305,
str::stream() << "histograms option to latencyStats must be bool, got "
<< elem
<< "of type "
<< typeName(elem.type()),
elem["histograms"].isBoolean());
}
} else if ("storageStats" == fieldName) {
uassert(40279,
str::stream() << "storageStats argument must be an object, but got " << elem
<< " of type "
<< typeName(elem.type()),
elem.type() == BSONType::Object);
} else if ("count" == fieldName) {
uassert(40480,
str::stream() << "count argument must be an object, but got " << elem
<< " of type "
<< typeName(elem.type()),
elem.type() == BSONType::Object);
} else {
uasserted(40168, str::stream() << "unrecognized option to $collStats: " << fieldName);
}
}
collStats->_collStatsSpec = specElem.Obj().getOwned();
return collStats;
}
示例4: init
Status ModifierObjectReplace::init(const BSONElement& modExpr,
const Options& opts,
bool* positional) {
if (modExpr.type() != Object) {
// Impossible, really since the caller check this already...
return Status(ErrorCodes::BadValue,
str::stream() << "Document replacement expects a complete document"
" but the type supplied was " << modExpr.type());
}
// Object replacements never have positional operator.
if (positional)
*positional = false;
// We make a copy of the object here because the update driver does not guarantees, in
// the case of object replacement, that the modExpr is going to outlive this mod.
_val = modExpr.embeddedObject().getOwned();
return fixupTimestamps(_val);
}
示例5: unserialize
void DBConfig::unserialize(const BSONObj& from){
_name = from.getStringField("name");
_shardingEnabled = from.getBoolField("partitioned");
_primary = from.getStringField("primary");
_sharded.clear();
BSONObj sharded = from.getObjectField( "sharded" );
if ( ! sharded.isEmpty() ){
BSONObjIterator i(sharded);
while ( i.more() ){
BSONElement e = i.next();
uassert( 10182 , "sharded things have to be objects" , e.type() == Object );
BSONObj c = e.embeddedObject();
uassert( 10183 , "key has to be an object" , c["key"].type() == Object );
_sharded[e.fieldName()] = CollectionInfo( c["key"].embeddedObject() ,
c["unique"].trueValue() );
}
}
}
示例6: DocumentSourceInternalSplitPipeline
boost::intrusive_ptr<DocumentSource> DocumentSourceInternalSplitPipeline::createFromBson(
BSONElement elem, const boost::intrusive_ptr<ExpressionContext>& expCtx) {
uassert(ErrorCodes::TypeMismatch,
str::stream() << "$_internalSplitPipeline must take a nested object but found: "
<< elem,
elem.type() == BSONType::Object);
auto specObj = elem.embeddedObject();
HostTypeRequirement mergeType = HostTypeRequirement::kNone;
for (auto&& elt : specObj) {
if (elt.fieldNameStringData() == "mergeType"_sd) {
uassert(ErrorCodes::BadValue,
str::stream() << "'mergeType' must be a string value but found: " << elt.type(),
elt.type() == BSONType::String);
auto mergeTypeString = elt.valueStringData();
if ("localOnly"_sd == mergeTypeString) {
mergeType = HostTypeRequirement::kLocalOnly;
} else if ("anyShard"_sd == mergeTypeString) {
mergeType = HostTypeRequirement::kAnyShard;
} else if ("primaryShard"_sd == mergeTypeString) {
mergeType = HostTypeRequirement::kPrimaryShard;
} else if ("mongos"_sd == mergeTypeString) {
mergeType = HostTypeRequirement::kMongoS;
} else {
uasserted(ErrorCodes::BadValue,
str::stream() << "unrecognized field while parsing mergeType: '"
<< elt.fieldNameStringData()
<< "'");
}
} else {
uasserted(ErrorCodes::BadValue,
str::stream() << "unrecognized field while parsing $_internalSplitPipeline: '"
<< elt.fieldNameStringData()
<< "'");
}
}
return new DocumentSourceInternalSplitPipeline(expCtx, mergeType);
}
示例7: recursiveHash
void BSONElementHasher::recursiveHash( Hasher* h ,
const BSONElement& e ,
bool includeFieldName ) {
int canonicalType = e.canonicalType();
h->addData( &canonicalType , sizeof( canonicalType ) );
if ( includeFieldName ){
h->addData( e.fieldName() , e.fieldNameSize() );
}
if ( !e.mayEncapsulate() ){
//if there are no embedded objects (subobjects or arrays),
//compute the hash, squashing numeric types to 64-bit ints
if ( e.isNumber() ){
long long int i = e.safeNumberLong(); //well-defined for troublesome doubles
h->addData( &i , sizeof( i ) );
}
else {
h->addData( e.value() , e.valuesize() );
}
}
else {
//else identify the subobject.
//hash any preceding stuff (in the case of codeWscope)
//then each sub-element
//then finish with the EOO element.
BSONObj b;
if ( e.type() == CodeWScope ) {
h->addData( e.codeWScopeCode() , e.codeWScopeCodeLen() );
b = e.codeWScopeObject();
}
else {
b = e.embeddedObject();
}
BSONObjIterator i(b);
while( i.moreWithEOO() ) {
BSONElement el = i.next();
recursiveHash( h , el , true );
}
}
}
示例8: while
boost::optional<Document> DocumentSourceCommandShards::getNext() {
pExpCtx->checkForInterrupt();
while(true) {
if (!pBsonSource.get()) {
/* if there aren't any more futures, we're done */
if (iterator == listEnd)
return boost::none;
/* grab the next command result */
BSONObj resultObj = iterator->result;
uassert(16390, str::stream() << "sharded pipeline failed on shard " <<
iterator->shardTarget.getName() << ": " <<
resultObj.toString(),
resultObj["ok"].trueValue());
/* grab the result array out of the shard server's response */
BSONElement resultArray = resultObj["result"];
massert(16391, str::stream() << "no result array? shard:" <<
iterator->shardTarget.getName() << ": " <<
resultObj.toString(),
resultArray.type() == Array);
// done with error checking, don't need the shard name anymore
++iterator;
if (resultArray.embeddedObject().isEmpty()){
// this shard had no results, on to the next one
continue;
}
pBsonSource = DocumentSourceBsonArray::create(&resultArray, pExpCtx);
}
if (boost::optional<Document> out = pBsonSource->getNext())
return out;
// Source exhausted. Try next.
pBsonSource.reset();
}
}
示例9: init
Status LiteParsedQuery::init(const string& ns, int ntoskip, int ntoreturn, int queryOptions,
const BSONObj& queryObj, const BSONObj& proj,
bool fromQueryMessage) {
_ns = ns;
_ntoskip = ntoskip;
_ntoreturn = ntoreturn;
_options = queryOptions;
_proj = proj.getOwned();
if (_ntoskip < 0) {
return Status(ErrorCodes::BadValue, "bad skip value in query");
}
if (_ntoreturn < 0) {
// _ntoreturn greater than zero is simply a hint on how many objects to send back per
// "cursor batch". A negative number indicates a hard limit.
_wantMore = false;
_ntoreturn = -_ntoreturn;
}
if (fromQueryMessage) {
BSONElement queryField = queryObj["query"];
if (!queryField.isABSONObj()) { queryField = queryObj["$query"]; }
if (queryField.isABSONObj()) {
_filter = queryField.embeddedObject().getOwned();
Status status = initFullQuery(queryObj);
if (!status.isOK()) { return status; }
}
else {
// TODO: Does this ever happen?
_filter = queryObj.getOwned();
}
}
else {
// This is the debugging code path.
_filter = queryObj.getOwned();
}
_hasReadPref = queryObj.hasField("$readPreference");
return Status::OK();
}
示例10: isLegacyCenterSphere
static bool isLegacyCenterSphere(const BSONObj &obj) {
BSONObjIterator typeIt(obj);
BSONElement type = typeIt.next();
if (!type.isABSONObj()) { return false; }
bool isCenterSphere = mongoutils::str::equals(type.fieldName(), "$centerSphere");
if (!isCenterSphere) { return false; }
BSONObjIterator objIt(type.embeddedObject());
BSONElement center = objIt.next();
if (!center.isABSONObj()) { return false; }
if (!isLegacyPoint(center.Obj())) { return false; }
// Check to make sure the points are valid lng/lat.
BSONObjIterator coordIt(center.Obj());
BSONElement lng = coordIt.next();
BSONElement lat = coordIt.next();
if (!isValidLngLat(lng.Number(), lat.Number())) { return false; }
if (!objIt.more()) { return false; }
BSONElement radius = objIt.next();
if (!radius.isNumber()) { return false; }
return true;
}
示例11: parsePolygon
bool GeoParser::parsePolygon(const BSONObj &obj, PolygonWithCRS *out) {
if (isGeoJSONPolygon(obj)) {
const vector<BSONElement>& coordinates = obj.getFieldDotted(GEOJSON_COORDINATES).Array();
if (!parseGeoJSONPolygonCoordinates(coordinates, obj, &out->polygon)) { return false; }
out->crs = SPHERE;
} else {
BSONObjIterator typeIt(obj);
BSONElement type = typeIt.next();
BSONObjIterator coordIt(type.embeddedObject());
vector<Point> points;
while (coordIt.more()) {
Point p;
if (!parseLegacyPoint(coordIt.next().Obj(), &p)) { return false; }
points.push_back(p);
}
out->oldPolygon = Polygon(points);
out->crs = FLAT;
}
return true;
}
示例12: getFieldDottedOrArray
BSONElement BSONObj::getFieldDottedOrArray(const char *&name) const {
const char *p = strchr(name, '.');
string left;
if ( p ) {
left = string(name, p-name);
name = p + 1;
} else {
left = string(name);
name = name + strlen(name);
}
BSONElement sub = getField(left.c_str());
if ( sub.eoo() )
return nullElement;
else if ( sub.type() == Array || strlen( name ) == 0 )
return sub;
else if ( sub.type() == Object )
return sub.embeddedObject().getFieldDottedOrArray( name );
else
return nullElement;
}
示例13: parseCommandCursorOptions
Status Command::parseCommandCursorOptions(const BSONObj& cmdObj,
long long defaultBatchSize,
long long* batchSize) {
invariant(batchSize);
*batchSize = defaultBatchSize;
BSONElement cursorElem = cmdObj["cursor"];
if (cursorElem.eoo()) {
return Status::OK();
}
if (cursorElem.type() != mongo::Object) {
return Status(ErrorCodes::TypeMismatch, "cursor field must be missing or an object");
}
BSONObj cursor = cursorElem.embeddedObject();
BSONElement batchSizeElem = cursor["batchSize"];
const int expectedNumberOfCursorFields = batchSizeElem.eoo() ? 0 : 1;
if (cursor.nFields() != expectedNumberOfCursorFields) {
return Status(ErrorCodes::BadValue,
"cursor object can't contain fields other than batchSize");
}
if (batchSizeElem.eoo()) {
return Status::OK();
}
if (!batchSizeElem.isNumber()) {
return Status(ErrorCodes::TypeMismatch, "cursor.batchSize must be a number");
}
// This can change in the future, but for now all negatives are reserved.
if (batchSizeElem.numberLong() < 0) {
return Status(ErrorCodes::BadValue, "cursor.batchSize must not be negative");
}
*batchSize = batchSizeElem.numberLong();
return Status::OK();
}
示例14: parseLegacyQuery
bool NearQuery::parseLegacyQuery(const BSONObj &obj) {
bool hasGeometry = false;
// First, try legacy near, e.g.:
// t.find({ loc : { $nearSphere: [0,0], $minDistance: 1, $maxDistance: 3 }})
// t.find({ loc : { $nearSphere: [0,0] }})
// t.find({ loc : { $near : [0, 0, 1] } });
// t.find({ loc : { $near: { someGeoJSONPoint}})
// t.find({ loc : { $geoNear: { someGeoJSONPoint}})
BSONObjIterator it(obj);
while (it.more()) {
BSONElement e = it.next();
if (equals(e.fieldName(), "$near") || equals(e.fieldName(), "$geoNear")
|| equals(e.fieldName(), "$nearSphere")) {
if (!e.isABSONObj()) {
return false;
}
BSONObj embeddedObj = e.embeddedObject();
if ((GeoParser::isPoint(embeddedObj) && GeoParser::parsePoint(embeddedObj, ¢roid))
|| GeoParser::parsePointWithMaxDistance(embeddedObj, ¢roid, &maxDistance)) {
uassert(18522, "max distance must be non-negative", maxDistance >= 0.0);
hasGeometry = true;
isNearSphere = equals(e.fieldName(), "$nearSphere");
}
} else if (equals(e.fieldName(), "$minDistance")) {
uassert(16893, "$minDistance must be a number", e.isNumber());
minDistance = e.Number();
uassert(16894, "$minDistance must be non-negative", minDistance >= 0.0);
} else if (equals(e.fieldName(), "$maxDistance")) {
uassert(16895, "$maxDistance must be a number", e.isNumber());
maxDistance = e.Number();
uassert(16896, "$maxDistance must be non-negative", maxDistance >= 0.0);
} else if (equals(e.fieldName(), "$uniqueDocs")) {
warning() << "ignoring deprecated option $uniqueDocs";
}
}
return hasGeometry;
}
示例15: unserialize
void Chunk::unserialize(const BSONObj& from){
_ns = from.getStringField( "ns" );
_shard = from.getStringField( "shard" );
_lastmod = from.hasField( "lastmod" ) ? from["lastmod"]._numberLong() : 0;
BSONElement e = from["minDotted"];
cout << from << endl;
if (e.eoo()){
_min = from.getObjectField( "min" ).getOwned();
_max = from.getObjectField( "max" ).getOwned();
} else { // TODO delete this case after giving people a chance to migrate
_min = e.embeddedObject().getOwned();
_max = from.getObjectField( "maxDotted" ).getOwned();
}
uassert( 10170 , "Chunk needs a ns" , ! _ns.empty() );
uassert( 10171 , "Chunk needs a server" , ! _ns.empty() );
uassert( 10172 , "Chunk needs a min" , ! _min.isEmpty() );
uassert( 10173 , "Chunk needs a max" , ! _max.isEmpty() );
}