本文整理汇总了C++中BSONElement::isABSONObj方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::isABSONObj方法的具体用法?C++ BSONElement::isABSONObj怎么用?C++ BSONElement::isABSONObj使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::isABSONObj方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: childrenMatch
/**
* Looks in the children stored in the 'nodes' field of 'testSoln'
* to see if thet match the 'children' field of 'trueSoln'.
*
* This does an unordered comparison, i.e. childrenMatch returns
* true as long as the set of subtrees in testSoln's 'nodes' matches
* the set of subtrees in trueSoln's 'children' vector.
*/
static bool childrenMatch(const BSONObj& testSoln, const QuerySolutionNode* trueSoln) {
BSONElement children = testSoln["nodes"];
if (children.eoo() || !children.isABSONObj()) {
return false;
}
// The order of the children array in testSoln might not match
// the order in trueSoln, so we have to check all combos with
// these nested loops.
BSONObjIterator i(children.Obj());
while (i.more()) {
BSONElement child = i.next();
if (child.eoo() || !child.isABSONObj()) {
return false;
}
// try to match against one of the QuerySolutionNode's children
bool found = false;
for (size_t j = 0; j < trueSoln->children.size(); ++j) {
if (QueryPlannerTestLib::solutionMatches(child.Obj(), trueSoln->children[j])) {
found = true;
break;
}
}
// we couldn't match child
if (!found) {
return false;
}
}
return true;
}
示例2: StartMongoProgram
// This function starts a program. In its input array it accepts either all commandline tokens
// which will be executed, or a single Object which must have a field named "args" which contains
// an array with all commandline tokens. The Object may have a field named "env" which contains an
// object of Key Value pairs which will be loaded into the environment of the spawned process.
BSONObj StartMongoProgram(const BSONObj& a, void* data) {
_nokillop = true;
BSONObj args = a;
BSONObj env{};
BSONElement firstElement = args.firstElement();
if (firstElement.ok() && firstElement.isABSONObj()) {
BSONObj subobj = firstElement.Obj();
BSONElement argsElem = subobj["args"];
BSONElement envElem = subobj["env"];
uassert(40098,
"If StartMongoProgram is called with a BSONObj, "
"it must contain an 'args' subobject." +
args.toString(),
argsElem.ok() && argsElem.isABSONObj());
args = argsElem.Obj();
if (envElem.ok() && envElem.isABSONObj()) {
env = envElem.Obj();
}
}
ProgramRunner r(args, env);
r.start();
invariant(registry.isPidRegistered(r.pid()));
stdx::thread t(r);
registry.registerReaderThread(r.pid(), std::move(t));
return BSON(string("") << r.pid().asLongLong());
}
示例3: init
void ParsedQuery::init( const BSONObj& q ) {
_reset();
uassert( 10105 , "bad skip value in query", _ntoskip >= 0);
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;
}
BSONElement e = q["query"];
if ( ! e.isABSONObj() )
e = q["$query"];
if ( e.isABSONObj() ) {
_filter = e.embeddedObject().getOwned();
_initTop( q );
}
else {
_filter = q.getOwned();
}
_hasReadPref = q.hasField(Query::ReadPrefField.name());
}
示例4: _phraseRecurse
/*
* Recurses over all fields in the obj to match against phrase
* @param phrase, string to be matched
* @param obj, object to matched against
*/
bool FTSMatcher::_phraseRecurse( const string& phrase, const BSONObj& obj ) const {
BSONObjIterator j( obj );
while ( j.more() ) {
BSONElement x = j.next();
if ( _spec.languageOverrideField() == x.fieldName() )
continue;
if ( x.type() == String ) {
if ( _phraseMatches( phrase, x.String() ) )
return true;
}
else if ( x.isABSONObj() ) {
BSONObjIterator k( x.Obj() );
while ( k.more() ) {
BSONElement y = k.next();
if ( y.type() == mongo::String ) {
if ( _phraseMatches( phrase, y.String() ) )
return true;
}
else if ( y.isABSONObj() ) {
if ( _phraseRecurse( phrase, y.Obj() ) )
return true;
}
}
}
}
return false;
}
示例5: _hasNegativeTerm_recurse
bool FTSMatcher::_hasNegativeTerm_recurse(const BSONObj& obj ) const {
BSONObjIterator j( obj );
while ( j.more() ) {
BSONElement x = j.next();
if ( _spec.languageOverrideField() == x.fieldName())
continue;
if (x.type() == String) {
if ( _hasNegativeTerm_string( x.String() ) )
return true;
}
else if ( x.isABSONObj() ) {
BSONObjIterator k( x.Obj() );
while ( k.more() ) {
// check if k.next() is a obj/array or not
BSONElement y = k.next();
if ( y.type() == String ) {
if ( _hasNegativeTerm_string( y.String() ) )
return true;
}
else if ( y.isABSONObj() ) {
if ( _hasNegativeTerm_recurse( y.Obj() ) )
return true;
}
}
}
}
return false;
}
示例6: run
bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result,
bool fromRepl) {
BSONElement argElt = cmdObj["stageDebug"];
if (argElt.eoo() || !argElt.isABSONObj()) { return false; }
BSONObj argObj = argElt.Obj();
// Pull out the collection name.
BSONElement collElt = argObj["collection"];
if (collElt.eoo() || (String != collElt.type())) {
return false;
}
string collName = collElt.String();
// Need a context to get the actual Collection*
// TODO A write lock is currently taken here to accommodate stages that perform writes
// (e.g. DeleteStage). This should be changed to use a read lock for read-only
// execution trees.
ScopedTransaction transaction(txn, MODE_IX);
Lock::DBLock lk(txn->lockState(), dbname, MODE_X);
Client::Context ctx(txn, dbname);
// Make sure the collection is valid.
Database* db = ctx.db();
Collection* collection = db->getCollection(db->name() + '.' + collName);
uassert(17446, "Couldn't find the collection " + collName, NULL != collection);
// Pull out the plan
BSONElement planElt = argObj["plan"];
if (planElt.eoo() || !planElt.isABSONObj()) {
return false;
}
BSONObj planObj = planElt.Obj();
// Parse the plan into these.
OwnedPointerVector<MatchExpression> exprs;
auto_ptr<WorkingSet> ws(new WorkingSet());
PlanStage* userRoot = parseQuery(txn, collection, planObj, ws.get(), &exprs);
uassert(16911, "Couldn't parse plan from " + cmdObj.toString(), NULL != userRoot);
// Add a fetch at the top for the user so we can get obj back for sure.
// TODO: Do we want to do this for the user? I think so.
PlanStage* rootFetch = new FetchStage(txn, ws.get(), userRoot, NULL, collection);
PlanExecutor* rawExec;
Status execStatus = PlanExecutor::make(txn, ws.release(), rootFetch, collection,
PlanExecutor::YIELD_MANUAL, &rawExec);
fassert(28536, execStatus);
boost::scoped_ptr<PlanExecutor> exec(rawExec);
BSONArrayBuilder resultBuilder(result.subarrayStart("results"));
for (BSONObj obj; PlanExecutor::ADVANCED == exec->getNext(&obj, NULL); ) {
resultBuilder.append(obj);
}
resultBuilder.done();
return true;
}
示例7: parseNewQuery
bool GeoQuery::parseNewQuery(const BSONObj &obj) {
// pointA = { "type" : "Point", "coordinates": [ 40, 5 ] }
// t.find({ "geo" : { "$intersect" : { "$geometry" : pointA} } })
// t.find({ "geo" : { "$within" : { "$geometry" : polygon } } })
// where field.name is "geo"
BSONElement e = obj.firstElement();
if (!e.isABSONObj()) {
return false;
}
BSONObj::MatchType matchType = static_cast<BSONObj::MatchType>(e.getGtLtOp());
if (BSONObj::opGEO_INTERSECTS == matchType) {
predicate = GeoQuery::INTERSECT;
} else if (BSONObj::opWITHIN == matchType) {
predicate = GeoQuery::WITHIN;
} else {
return false;
}
bool hasGeometry = false;
BSONObjIterator argIt(e.embeddedObject());
while (argIt.more()) {
BSONElement e = argIt.next();
if (mongoutils::str::equals(e.fieldName(), "$geometry")) {
if (e.isABSONObj()) {
BSONObj embeddedObj = e.embeddedObject();
if (geoContainer.parseFrom(embeddedObj)) {
hasGeometry = true;
}
}
}
}
// Don't want to give the error below if we could not pull any geometry out.
if (!hasGeometry) {
return false;
}
if (GeoQuery::WITHIN == predicate) {
// Why do we only deal with $within {polygon}?
// 1. Finding things within a point is silly and only valid
// for points and degenerate lines/polys.
//
// 2. Finding points within a line is easy but that's called intersect.
// Finding lines within a line is kind of tricky given what S2 gives us.
// Doing line-within-line is a valid yet unsupported feature,
// though I wonder if we want to preserve orientation for lines or
// allow (a,b),(c,d) to be within (c,d),(a,b). Anyway, punt on
// this for now.
uassert(16672, "$within not supported with provided geometry: " + obj.toString(),
geoContainer.supportsContains());
}
return hasGeometry;
}
示例8: isLegacyBox
bool GeoParser::isLegacyBox(const BSONObj &obj) {
BSONObjIterator coordIt(obj);
BSONElement minE = coordIt.next();
if (!minE.isABSONObj()) { return false; }
if (!isLegacyPoint(minE.Obj())) { return false; }
if (!coordIt.more()) { return false; }
BSONElement maxE = coordIt.next();
if (!maxE.isABSONObj()) { return false; }
if (!isLegacyPoint(maxE.Obj())) { return false; }
return true;
}
示例9: init
void ParsedQuery::init( const BSONObj& q ) {
_reset();
uassert( 10105 , "bad skip value in query", _ntoskip >= 0);
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;
}
BSONElement e = q["query"];
if ( ! e.isABSONObj() )
e = q["$query"];
if ( e.isABSONObj() ) {
_filter = e.embeddedObject();
_initTop( q );
}
else {
_filter = q;
}
_filter = _filter.getOwned();
//
// Parse options that are valid for both queries and commands
//
// $readPreference
_hasReadPref = q.hasField(Query::ReadPrefField.name());
// $maxTimeMS
BSONElement maxTimeMSElt = q.getField("$maxTimeMS");
if (!maxTimeMSElt.eoo()) {
uassert(16987,
mongoutils::str::stream() <<
"$maxTimeMS must be a number type, instead found type: " <<
maxTimeMSElt.type(),
maxTimeMSElt.isNumber());
}
// If $maxTimeMS was not specified, _maxTimeMS is set to 0 (special value for "allow to
// run indefinitely").
long long maxTimeMSLongLong = maxTimeMSElt.safeNumberLong();
uassert(16988,
"$maxTimeMS out of range [0,2147483647]",
maxTimeMSLongLong >= 0 && maxTimeMSLongLong <= INT_MAX);
_maxTimeMS = static_cast<int>(maxTimeMSLongLong);
}
示例10: canonicalize
// static
Status PlanCacheCommand::canonicalize(OperationContext* txn,
const string& ns,
const BSONObj& cmdObj,
CanonicalQuery** canonicalQueryOut) {
// query - required
BSONElement queryElt = cmdObj.getField("query");
if (queryElt.eoo()) {
return Status(ErrorCodes::BadValue, "required field query missing");
}
if (!queryElt.isABSONObj()) {
return Status(ErrorCodes::BadValue, "required field query must be an object");
}
if (queryElt.eoo()) {
return Status(ErrorCodes::BadValue, "required field query missing");
}
BSONObj queryObj = queryElt.Obj();
// sort - optional
BSONElement sortElt = cmdObj.getField("sort");
BSONObj sortObj;
if (!sortElt.eoo()) {
if (!sortElt.isABSONObj()) {
return Status(ErrorCodes::BadValue, "optional field sort must be an object");
}
sortObj = sortElt.Obj();
}
// projection - optional
BSONElement projElt = cmdObj.getField("projection");
BSONObj projObj;
if (!projElt.eoo()) {
if (!projElt.isABSONObj()) {
return Status(ErrorCodes::BadValue, "optional field projection must be an object");
}
projObj = projElt.Obj();
}
// Create canonical query
CanonicalQuery* cqRaw;
const NamespaceString nss(ns);
const WhereCallbackReal whereCallback(txn, nss.db());
Status result = CanonicalQuery::canonicalize(
ns, queryObj, sortObj, projObj, &cqRaw, whereCallback);
if (!result.isOK()) {
return result;
}
*canonicalQueryOut = cqRaw;
return Status::OK();
}
示例11: Status
// static
StatusWith<unique_ptr<CanonicalQuery>> PlanCacheCommand::canonicalize(OperationContext* txn,
const string& ns,
const BSONObj& cmdObj) {
// query - required
BSONElement queryElt = cmdObj.getField("query");
if (queryElt.eoo()) {
return Status(ErrorCodes::BadValue, "required field query missing");
}
if (!queryElt.isABSONObj()) {
return Status(ErrorCodes::BadValue, "required field query must be an object");
}
if (queryElt.eoo()) {
return Status(ErrorCodes::BadValue, "required field query missing");
}
BSONObj queryObj = queryElt.Obj();
// sort - optional
BSONElement sortElt = cmdObj.getField("sort");
BSONObj sortObj;
if (!sortElt.eoo()) {
if (!sortElt.isABSONObj()) {
return Status(ErrorCodes::BadValue, "optional field sort must be an object");
}
sortObj = sortElt.Obj();
}
// projection - optional
BSONElement projElt = cmdObj.getField("projection");
BSONObj projObj;
if (!projElt.eoo()) {
if (!projElt.isABSONObj()) {
return Status(ErrorCodes::BadValue, "optional field projection must be an object");
}
projObj = projElt.Obj();
}
// Create canonical query
const NamespaceString nss(ns);
auto qr = stdx::make_unique<QueryRequest>(std::move(nss));
qr->setFilter(queryObj);
qr->setSort(sortObj);
qr->setProj(projObj);
const ExtensionsCallbackReal extensionsCallback(txn, &nss);
auto statusWithCQ = CanonicalQuery::canonicalize(txn, std::move(qr), extensionsCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
return std::move(statusWithCQ.getValue());
}
示例12: isLegacyCenter
static bool isLegacyCenter(const BSONObj &obj) {
BSONObjIterator typeIt(obj);
BSONElement type = typeIt.next();
if (!type.isABSONObj()) { return false; }
bool isCenter = mongoutils::str::equals(type.fieldName(), "$center");
if (!isCenter) { return false; }
BSONObjIterator objIt(type.embeddedObject());
BSONElement center = objIt.next();
if (!center.isABSONObj()) { return false; }
if (!isLegacyPoint(center.Obj())) { return false; }
if (!objIt.more()) { return false; }
BSONElement radius = objIt.next();
if (!radius.isNumber()) { return false; }
return true;
}
示例13: isLegacyBox
bool GeoParser::isLegacyBox(const BSONObj &obj) {
BSONObjIterator typeIt(obj);
BSONElement type = typeIt.next();
if (!type.isABSONObj()) { return false; }
if (!mongoutils::str::equals(type.fieldName(), "$box")) { return false; }
BSONObjIterator coordIt(type.embeddedObject());
BSONElement minE = coordIt.next();
if (!minE.isABSONObj()) { return false; }
if (!isLegacyPoint(minE.Obj())) { return false; }
if (!coordIt.more()) { return false; }
BSONElement maxE = coordIt.next();
if (!maxE.isABSONObj()) { return false; }
if (!isLegacyPoint(maxE.Obj())) { return false; }
return true;
}
示例14: RecordId
void BSONCollectionCatalogEntry::MetaData::parse(const BSONObj& obj) {
ns = obj["ns"].valuestrsafe();
if (obj["options"].isABSONObj()) {
options.parse(obj["options"].Obj(), CollectionOptions::parseForStorage)
.transitional_ignore();
}
BSONElement indexList = obj["indexes"];
if (indexList.isABSONObj()) {
for (BSONElement elt : indexList.Obj()) {
BSONObj idx = elt.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();
if (auto multikeyPathsElem = idx["multikeyPaths"]) {
parseMultikeyPathsFromBytes(multikeyPathsElem.Obj(), &imd.multikeyPaths);
}
imd.prefix = KVPrefix::fromBSONElement(idx["prefix"]);
indexes.push_back(imd);
}
}
prefix = KVPrefix::fromBSONElement(obj["prefix"]);
}
示例15: matchesSingleElement
bool GeoMatchExpression::matchesSingleElement( const BSONElement& e ) const {
if ( !e.isABSONObj())
return false;
GeometryContainer geometry;
if ( !geometry.parseFromStorage( e ).isOK() )
return false;
// Never match big polygon
if (geometry.getNativeCRS() == STRICT_SPHERE)
return false;
// Project this geometry into the CRS of the query
if (!geometry.supportsProject(_query->getGeometry().getNativeCRS()))
return false;
geometry.projectInto(_query->getGeometry().getNativeCRS());
if (GeoExpression::WITHIN == _query->getPred()) {
return _query->getGeometry().contains(geometry);
}
else {
verify(GeoExpression::INTERSECT == _query->getPred());
return _query->getGeometry().intersects(geometry);
}
}