本文整理汇总了C++中BSONObj::getFieldDotted方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObj::getFieldDotted方法的具体用法?C++ BSONObj::getFieldDotted怎么用?C++ BSONObj::getFieldDotted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObj
的用法示例。
在下文中一共展示了BSONObj::getFieldDotted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applyRefOp
// find all oplog entries for a given OID in the oplog.refs collection and apply them
// TODO this should be a range query on oplog.refs where _id.oid == oid and applyOps to
// each entry found. The locking of the query interleaved with the locking in the applyOps
// did not work, so it a sequence of point queries.
// TODO verify that the query plan is a indexed lookup.
// TODO verify that the query plan does not fetch too many docs and then only process one of them.
void applyRefOp(BSONObj entry) {
OID oid = entry["ref"].OID();
LOG(3) << "apply ref " << entry << " oid " << oid << endl;
long long seq = 0; // note that 0 is smaller than any of the seq numbers
while (1) {
BSONObj entry;
{
LOCK_REASON(lockReason, "repl: finding oplog.refs entry to apply");
Client::ReadContext ctx(rsOplogRefs, lockReason);
// TODO: Should this be using rsOplogRefsDetails, verifying non-null?
Collection *cl = getCollection(rsOplogRefs);
if (cl == NULL || !cl->findOne(BSON("_id" << BSON("$gt" << BSON("oid" << oid << "seq" << seq))), entry, true)) {
break;
}
}
BSONElement e = entry.getFieldDotted("_id.seq");
seq = e.Long();
BSONElement eOID = entry.getFieldDotted("_id.oid");
if (oid != eOID.OID()) {
break;
}
LOG(3) << "apply " << entry << " seq=" << seq << endl;
applyOps(entry["ops"].Array());
}
}
示例2: diff
double StatUtil::diff( const string& name , const BSONObj& a , const BSONObj& b ) {
BSONElement x = a.getFieldDotted( name.c_str() );
BSONElement y = b.getFieldDotted( name.c_str() );
if ( ! x.isNumber() || ! y.isNumber() )
return -1;
return ( y.number() - x.number() ) / _seconds;
}
示例3: 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;
}
示例4: percent
double StatUtil::percent( const char * outof , const char * val , const BSONObj& a , const BSONObj& b ) {
double x = ( b.getFieldDotted( val ).number() - a.getFieldDotted( val ).number() );
double y = ( b.getFieldDotted( outof ).number() - a.getFieldDotted( outof ).number() );
if ( y == 0 )
return 0;
double p = x / y;
p = (double)((int)(p * 1000)) / 10;
return p;
}
示例5: 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());
}
示例6: 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());
}
示例7: parsePolygon
bool GeoParser::parsePolygon(const BSONObj &obj, PolygonWithCRS *out) {
if (isGeoJSONPolygon(obj)) {
const vector<BSONElement>& coordinates = obj.getFieldDotted(GEOJSON_COORDINATES).Array();
if (!parseGeoJSONCRS(obj, &out->crs))
return false;
if (out->crs == SPHERE) {
out->s2Polygon.reset(new S2Polygon());
if (!parseGeoJSONPolygonCoordinates(coordinates, obj, out->s2Polygon.get())) {
return false;
}
}
else if (out->crs == STRICT_SPHERE) {
out->bigPolygon.reset(new BigSimplePolygon());
if (!parseBigSimplePolygonCoordinates(coordinates, obj, out->bigPolygon.get())) {
return false;
}
}
} 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.init(points);
out->crs = FLAT;
}
return true;
}
示例8:
ShardStatus::ShardStatus( const Shard& shard , const BSONObj& obj , const BSONObj& dblistobj )
: _shard( shard ), _isDraining(shard.isDraining()) {
_dataSize = dblistobj.getFieldDotted("totalUncompressedSize").numberLong();
_hasOpsQueued = obj["writeBacksQueued"].Bool();
_writeLock = 0; // TODO
_mongoVersion = obj["version"].String();
}
示例9: woSortOrder
/* well ordered compare */
int BSONObj::woSortOrder(const BSONObj& other, const BSONObj& sortKey , bool useDotted ) const {
if ( isEmpty() )
return other.isEmpty() ? 0 : -1;
if ( other.isEmpty() )
return 1;
uassert( 10060 , "woSortOrder needs a non-empty sortKey" , ! sortKey.isEmpty() );
BSONObjIterator i(sortKey);
while ( 1 ) {
BSONElement f = i.next();
if ( f.eoo() )
return 0;
BSONElement l = useDotted ? getFieldDotted( f.fieldName() ) : getField( f.fieldName() );
if ( l.eoo() )
l = staticNull.firstElement();
BSONElement r = useDotted ? other.getFieldDotted( f.fieldName() ) : other.getField( f.fieldName() );
if ( r.eoo() )
r = staticNull.firstElement();
int x = l.woCompare( r, false );
if ( f.number() < 0 )
x = -x;
if ( x != 0 )
return x;
}
return -1;
}
示例10: parseMultiPolygon
Status GeoParser::parseMultiPolygon(const BSONObj& obj,
bool skipValidation,
MultiPolygonWithCRS* out) {
Status status = Status::OK();
status = parseGeoJSONCRS(obj, &out->crs);
if (!status.isOK())
return status;
BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
if (Array != coordElt.type())
return BAD_VALUE("MultiPolygon coordinates must be an array");
out->polygons.clear();
vector<S2Polygon*>& polygons = out->polygons.mutableVector();
BSONObjIterator it(coordElt.Obj());
// Iterate array
while (it.more()) {
polygons.push_back(new S2Polygon());
status = parseGeoJSONPolygonCoordinates(it.next(), skipValidation, polygons.back());
if (!status.isOK())
return status;
}
if (0 == polygons.size())
return BAD_VALUE("MultiPolygon coordinates must have at least 1 element");
return Status::OK();
}
示例11: createSortedDataInterface
Status WiredTigerKVEngine::createSortedDataInterface(OperationContext* opCtx,
StringData ident,
const IndexDescriptor* desc) {
_checkIdentPath(ident);
std::string collIndexOptions;
const Collection* collection = desc->getCollection();
// Treat 'collIndexOptions' as an empty string when the collection member of 'desc' is NULL in
// order to allow for unit testing WiredTigerKVEngine::createSortedDataInterface().
if (collection) {
const CollectionCatalogEntry* cce = collection->getCatalogEntry();
const CollectionOptions collOptions = cce->getCollectionOptions(opCtx);
if (!collOptions.indexOptionDefaults["storageEngine"].eoo()) {
BSONObj storageEngineOptions = collOptions.indexOptionDefaults["storageEngine"].Obj();
collIndexOptions =
storageEngineOptions.getFieldDotted("wiredTiger.configString").valuestrsafe();
}
}
StatusWith<std::string> result =
WiredTigerIndex::generateCreateString(_indexOptions, collIndexOptions, *desc);
if (!result.isOK()) {
return result.getStatus();
}
std::string config = result.getValue();
LOG(2) << "WiredTigerKVEngine::createSortedDataInterface ident: " << ident
<< " config: " << config;
return wtRCToStatus(WiredTigerIndex::Create(opCtx, _uri(ident), config));
}
示例12: getKeys
void getKeys( const BSONObj &obj, BSONObjSet &keys ) const {
BSONElement loc = obj.getFieldDotted( _geo );
if ( loc.eoo() )
return;
uassert( 13323 , "latlng not an array" , loc.isABSONObj() );
string root;
{
BSONObjIterator i( loc.Obj() );
BSONElement x = i.next();
BSONElement y = i.next();
root = makeString( hash(x) , hash(y) );
}
verify( _other.size() == 1 );
BSONElementSet all;
obj.getFieldsDotted( _other[0] , all );
if ( all.size() == 0 ) {
_add( obj , root , BSONElement() , keys );
}
else {
for ( BSONElementSet::iterator i=all.begin(); i!=all.end(); ++i ) {
_add( obj , root , *i , keys );
}
}
}
示例13: getIndexPrefix
Status FTSSpec::getIndexPrefix( const BSONObj& query, BSONObj* out ) const {
if ( numExtraBefore() == 0 ) {
*out = BSONObj();
return Status::OK();
}
BSONObjBuilder b;
for ( unsigned i = 0; i < numExtraBefore(); i++ ) {
BSONElement e = query.getFieldDotted(extraBefore(i));
if ( e.eoo() )
return Status( ErrorCodes::BadValue,
str::stream()
<< "need have an equality filter on: "
<< extraBefore(i) );
if ( e.isABSONObj() && e.Obj().firstElement().getGtLtOp( -1 ) != -1 )
return Status( ErrorCodes::BadValue,
str::stream()
<< "need have an equality filter on: "
<< extraBefore(i) );
b.append( e );
}
*out = b.obj();
return Status::OK();
}
示例14: parseGeoJSONPolygon
void GeoParser::parseGeoJSONPolygon(const BSONObj& obj, S2Polygon* out) {
const vector<BSONElement>& coordinates =
obj.getFieldDotted(GEOJSON_COORDINATES).Array();
const vector<BSONElement>& exteriorRing = coordinates[0].Array();
vector<S2Point> exteriorVertices;
parsePoints(exteriorRing, &exteriorVertices);
S2PolygonBuilderOptions polyOptions;
polyOptions.set_validate(true);
S2PolygonBuilder polyBuilder(polyOptions);
S2Loop exteriorLoop(exteriorVertices);
if (exteriorLoop.is_hole()) {
exteriorLoop.Invert();
}
polyBuilder.AddLoop(&exteriorLoop);
// Subsequent arrays of coordinates are interior rings/holes.
for (size_t i = 1; i < coordinates.size(); ++i) {
vector<S2Point> holePoints;
parsePoints(coordinates[i].Array(), &holePoints);
// Interior rings are clockwise.
S2Loop holeLoop(holePoints);
if (!holeLoop.is_hole()) {
holeLoop.Invert();
}
polyBuilder.AddLoop(&holeLoop);
}
polyBuilder.AssemblePolygon(out, NULL);
}
示例15: handleCursorCommand
static void handleCursorCommand(CursorId id, BSONObj& cmdObj, BSONObjBuilder& result) {
BSONElement batchSizeElem = cmdObj.getFieldDotted("cursor.batchSize");
const long long batchSize = batchSizeElem.isNumber()
? batchSizeElem.numberLong()
: 101; // same as query
ClientCursorPin pin(id);
ClientCursor* cursor = pin.c();
massert(16958, "Cursor shouldn't have been deleted",
cursor);
verify(cursor->isAggCursor);
PipelineRunner* runner = dynamic_cast<PipelineRunner*>(cursor->getRunner());
verify(runner);
try {
const string cursorNs = cursor->ns(); // we need this after cursor may have been deleted
// can't use result BSONObjBuilder directly since it won't handle exceptions correctly.
BSONArrayBuilder resultsArray;
const int byteLimit = MaxBytesToReturnToClientAtOnce;
BSONObj next;
for (int objCount = 0; objCount < batchSize; objCount++) {
// The initial getNext() on a PipelineRunner may be very expensive so we don't do it
// when batchSize is 0 since that indicates a desire for a fast return.
if (runner->getNext(&next, NULL) != Runner::RUNNER_ADVANCED) {
pin.deleteUnderlying();
id = 0;
cursor = NULL; // make it an obvious error to use cursor after this point
break;
}
if (resultsArray.len() + next.objsize() > byteLimit) {
// too big. next will be the first doc in the second batch
runner->pushBack(next);
break;
}
resultsArray.append(next);
}
if (cursor) {
// If a time limit was set on the pipeline, remaining time is "rolled over" to the
// cursor (for use by future getmore ops).
cursor->setLeftoverMaxTimeMicros( cc().curop()->getRemainingMaxTimeMicros() );
}
BSONObjBuilder cursorObj(result.subobjStart("cursor"));
cursorObj.append("id", id);
cursorObj.append("ns", cursorNs);
cursorObj.append("firstBatch", resultsArray.arr());
cursorObj.done();
}
catch (...) {
// Clean up cursor on way out of scope.
pin.deleteUnderlying();
throw;
}
}