本文整理汇总了C++中BSONObjBuilder::appendAs方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObjBuilder::appendAs方法的具体用法?C++ BSONObjBuilder::appendAs怎么用?C++ BSONObjBuilder::appendAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObjBuilder
的用法示例。
在下文中一共展示了BSONObjBuilder::appendAs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLiteralKeysArray
void S2AccessMethod::getOneLiteralKey(const BSONElement& elt, BSONObjSet* out) const {
if (Array == elt.type()) {
getLiteralKeysArray(elt.Obj(), out);
} else {
// One thing, not an array, index as-is.
BSONObjBuilder b;
b.appendAs(elt, "");
out->insert(b.obj());
}
}
示例2: getChunk
GridFSChunk GridFile::getChunk( int n ) const {
_exists();
BSONObjBuilder b;
b.appendAs( _obj["_id"] , "files_id" );
b.append( "n" , n );
BSONObj o = _grid->_client.findOne( _grid->_chunksNS.c_str() , b.obj() );
uassert( 10014 , "chunk is empty!" , ! o.isEmpty() );
return GridFSChunk(o);
}
示例3: transform
Status ProjectionStage::transform(WorkingSetMember* member) {
// The default no-fast-path case.
if (ProjectionStageParams::NO_FAST_PATH == _projImpl) {
return _exec->transform(member);
}
BSONObjBuilder bob;
// Note that even if our fast path analysis is bug-free something that is
// covered might be invalidated and just be an obj. In this case we just go
// through the SIMPLE_DOC path which is still correct if the covered data
// is not available.
//
// SIMPLE_DOC implies that we expect an object so it's kind of redundant.
if ((ProjectionStageParams::SIMPLE_DOC == _projImpl) || member->hasObj()) {
// If we got here because of SIMPLE_DOC the planner shouldn't have messed up.
invariant(member->hasObj());
// Look at every field in the source document and see if we're including it.
BSONObjIterator inputIt(member->obj);
while (inputIt.more()) {
BSONElement elt = inputIt.next();
unordered_set<StringData, StringData::Hasher>::iterator fieldIt;
fieldIt = _includedFields.find(elt.fieldNameStringData());
if (_includedFields.end() != fieldIt) {
// If so, add it to the builder.
bob.append(elt);
}
}
}
else {
invariant(ProjectionStageParams::COVERED_ONE_INDEX == _projImpl);
// We're pulling data out of the key.
invariant(1 == member->keyData.size());
size_t keyIndex = 0;
// Look at every key element...
BSONObjIterator keyIterator(member->keyData[0].keyData);
while (keyIterator.more()) {
BSONElement elt = keyIterator.next();
// If we're supposed to include it...
if (_includeKey[keyIndex]) {
// Do so.
bob.appendAs(elt, _keyFieldNames[keyIndex]);
}
++keyIndex;
}
}
member->state = WorkingSetMember::OWNED_OBJ;
member->keyData.clear();
member->loc = DiskLoc();
member->obj = bob.obj();
return Status::OK();
}
示例4: append
void Projection::append( BSONObjBuilder& b , const BSONElement& e, const MatchDetails* details,
const ArrayOpType arrayOpType ) const {
FieldMap::const_iterator field = _fields.find( e.fieldName() );
if (field == _fields.end()) {
if (_include)
b.append(e);
}
else {
Projection& subfm = *field->second;
if ( ( subfm._fields.empty() && !subfm._special ) ||
!(e.type()==Object || e.type()==Array) ) {
// field map empty, or element is not an array/object
if (subfm._include)
b.append(e);
}
else if (e.type() == Object) {
BSONObjBuilder subb;
BSONObjIterator it(e.embeddedObject());
while (it.more()) {
subfm.append(subb, it.next(), details, arrayOpType);
}
b.append(e.fieldName(), subb.obj());
}
else { //Array
BSONObjBuilder matchedBuilder;
if ( details && ( arrayOpType == ARRAY_OP_POSITIONAL ||
arrayOpType == ARRAY_OP_POSITIONAL_KEYED )) {
// $ positional operator specified
LOG(4) << "projection: checking if element " << e << " matched spec: "
<< getSpec() << " match details: " << *details << endl;
uassert( 16352, mongoutils::str::stream() << "positional operator ("
<< e.fieldName()
<< ".$) requires corresponding field in query specifier",
details && details->hasElemMatchKey() );
uassert( 16353, "positional operator element mismatch",
! e.embeddedObject()[details->elemMatchKey()].eoo() );
// append as the first element in the projected array
matchedBuilder.appendAs( e.embeddedObject()[details->elemMatchKey()], "0" );
// append the key as the second element in the projected array
if ( arrayOpType == ARRAY_OP_POSITIONAL_KEYED ) {
matchedBuilder.append( "1", details->elemMatchKey() );
}
}
else {
// append exact array; no subarray matcher specified
subfm.appendArray( matchedBuilder, e.embeddedObject() );
}
b.appendArray( e.fieldName(), matchedBuilder.obj() );
}
}
}
示例5: appendElementHandlingGtLt
// If the element is something like:
// a : { $gt : 3 }
// we append
// a : 3
// else we just append the element.
//
void appendElementHandlingGtLt(BSONObjBuilder& b, const BSONElement& e) {
if ( e.type() == Object ) {
BSONElement fe = e.embeddedObject().firstElement();
const char *fn = fe.fieldName();
if ( fn[0] == '$' && fn[1] && fn[2] == 't' ) {
b.appendAs(fe, e.fieldName());
return;
}
}
b.append(e);
}
示例6: addKey
// Build a new BSONObj with root in it. If e is non-empty, append that to the key. Insert
// the BSONObj into keys.
void addKey(const string& root, const BSONElement& e, BSONObjSet& keys) const {
BSONObjBuilder buf;
buf.append("", root);
if (e.eoo())
buf.appendNull("");
else
buf.appendAs(e, "");
keys.insert(buf.obj());
}
示例7: _add
void _add( const BSONObj& obj, const string& root , const BSONElement& e , BSONObjSet& keys ) const {
BSONObjBuilder buf;
buf.append( "" , root );
if ( e.eoo() )
buf.appendNull( "" );
else
buf.appendAs( e , "" );
BSONObj key = buf.obj();
GEOQUADDEBUG( obj << "\n\t" << root << "\n\t" << key );
keys.insert( key );
}
示例8: keyPatternPathSet
StatusWith<BSONObj> ShardKeyPattern::extractShardKeyFromQuery(const BSONObj& basicQuery) const {
if (!isValid())
return StatusWith<BSONObj>(BSONObj());
// Extract equalities from query
CanonicalQuery* rawQuery;
Status queryStatus =
CanonicalQuery::canonicalize("", basicQuery, &rawQuery, WhereCallbackNoop());
if (!queryStatus.isOK())
return StatusWith<BSONObj>(queryStatus);
scoped_ptr<CanonicalQuery> query(rawQuery);
EqualityMatches equalities;
// TODO: Build the path set initially?
FieldRefSet keyPatternPathSet(_keyPatternPaths.vector());
// We only care about extracting the full key pattern paths - if they don't exist (or are
// conflicting), we don't contain the shard key.
Status eqStatus =
pathsupport::extractFullEqualityMatches(*query->root(), keyPatternPathSet, &equalities);
// NOTE: Failure to extract equality matches just means we return no shard key - it's not
// an error we propagate
if (!eqStatus.isOK())
return StatusWith<BSONObj>(BSONObj());
// Extract key from equalities
// NOTE: The method below is equivalent to constructing a BSONObj and running
// extractShardKeyFromMatchable, but doesn't require creating the doc.
BSONObjBuilder keyBuilder;
// Iterate the parsed paths to avoid re-parsing
for (OwnedPointerVector<FieldRef>::const_iterator it = _keyPatternPaths.begin();
it != _keyPatternPaths.end();
++it) {
const FieldRef& patternPath = **it;
BSONElement equalEl = findEqualityElement(equalities, patternPath);
if (!isShardKeyElement(equalEl, false))
return StatusWith<BSONObj>(BSONObj());
if (isHashedPattern()) {
keyBuilder.append(
patternPath.dottedField(),
BSONElementHasher::hash64(equalEl, BSONElementHasher::DEFAULT_HASH_SEED));
} else {
// NOTE: The equal element may *not* have the same field name as the path -
// nested $and, $eq, for example
keyBuilder.appendAs(equalEl, patternPath.dottedField());
}
}
dassert(isShardKey(keyBuilder.asTempObj()));
return StatusWith<BSONObj>(keyBuilder.obj());
}
示例9: toBSON
BSONObj BatchedUpsertDetail::toBSON() const {
BSONObjBuilder builder;
if (_isIndexSet)
builder.append(index(), _index);
// We're using the BSONObj to store the _id value.
if (_isUpsertedIDSet) {
builder.appendAs(_upsertedID.firstElement(), upsertedID());
}
return builder.obj();
}
示例10: toKeyFormat
BSONObj Helpers::toKeyFormat( const BSONObj& o , BSONObj& key ) {
BSONObjBuilder me;
BSONObjBuilder k;
BSONObjIterator i( o );
while ( i.more() ) {
BSONElement e = i.next();
k.append( e.fieldName() , 1 );
me.appendAs( e , "" );
}
key = k.obj();
return me.obj();
}
示例11: it
void nested2dotted(BSONObjBuilder& b, const BSONObj& obj, const string& base){
BSONObjIterator it(obj);
while (it.more()){
BSONElement e = it.next();
if (e.type() == Object){
string newbase = base + e.fieldName() + ".";
nested2dotted(b, e.embeddedObject(), newbase);
}else{
string newbase = base + e.fieldName();
b.appendAs(e, newbase.c_str());
}
}
}
示例12: extractFieldsUnDotted
/**
sets element field names to empty string
If a field in pattern is missing, it is omitted from the returned
object.
*/
BSONObj BSONObj::extractFieldsUnDotted(BSONObj pattern) const {
BSONObjBuilder b;
BSONObjIterator i(pattern);
while ( i.more() ) {
BSONElement e = i.next();
if ( e.eoo() )
break;
BSONElement x = getField(e.fieldName());
if ( !x.eoo() )
b.appendAs(x, "");
}
return b.obj();
}
示例13: getIndexKey
BSONObj FTSIndexFormat::getIndexKey(double weight,
const string& term,
const BSONObj& indexPrefix,
TextIndexVersion textIndexVersion) {
BSONObjBuilder b;
BSONObjIterator i(indexPrefix);
while (i.more()) {
b.appendAs(i.next(), "");
}
_appendIndexKey(b, weight, term, textIndexVersion);
return b.obj();
}
示例14: invariant
StatusWith<BSONObj> SortKeyGenerator::getSortKeyFromIndexKey(const WorkingSetMember& member) const {
invariant(member.getState() == WorkingSetMember::RID_AND_IDX);
invariant(!_sortHasMeta);
BSONObjBuilder sortKeyObj;
for (BSONElement specElt : _rawSortSpec) {
invariant(specElt.isNumber());
BSONElement sortKeyElt;
invariant(member.getFieldDotted(specElt.fieldName(), &sortKeyElt));
sortKeyObj.appendAs(sortKeyElt, "");
}
return sortKeyObj.obj();
}
示例15: createIndexScan
IndexScan* createIndexScan(BSONObj startKey,
BSONObj endKey,
bool startInclusive,
bool endInclusive,
int direction = 1) {
IndexCatalog* catalog = _coll->getIndexCatalog();
IndexDescriptor* descriptor = catalog->findIndexByKeyPattern(&_txn, BSON("x" << 1));
invariant(descriptor);
IndexScanParams params;
params.descriptor = descriptor;
params.direction = direction;
OrderedIntervalList oil("x");
BSONObjBuilder bob;
bob.appendAs(startKey.firstElement(), "");
bob.appendAs(endKey.firstElement(), "");
oil.intervals.push_back(Interval(bob.obj(), startInclusive, endInclusive));
params.bounds.fields.push_back(oil);
MatchExpression* filter = NULL;
return new IndexScan(&_txn, params, &_ws, filter);
}