本文整理汇总了C++中BSONObjBuilder::appendRegex方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObjBuilder::appendRegex方法的具体用法?C++ BSONObjBuilder::appendRegex怎么用?C++ BSONObjBuilder::appendRegex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObjBuilder
的用法示例。
在下文中一共展示了BSONObjBuilder::appendRegex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRegex
void testRegex() {
BSONObjBuilder b;
b.appendRegex("x", "foo");
BSONObj o = b.done();
BSONObjBuilder c;
c.appendRegex("x", "goo");
BSONObj p = c.done();
assert( !o.woEqual( p ) );
assert( o.woCompare( p ) < 0 );
{
BSONObjBuilder b;
b.appendRegex("r", "^foo");
BSONObj o = b.done();
assert( o.firstElement().simpleRegex() == "foo" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "^f?oo");
BSONObj o = b.done();
assert( o.firstElement().simpleRegex() == "" );
}
{
BSONObjBuilder b;
b.appendRegex("r", "^fz?oo");
BSONObj o = b.done();
assert( o.firstElement().simpleRegex() == "f" );
}
}
示例2: testRegex
void testRegex() {
BSONObjBuilder b;
b.appendRegex("x", "foo");
BSONObj o = b.done();
BSONObjBuilder c;
c.appendRegex("x", "goo");
BSONObj p = c.done();
assert( !o.woEqual( p ) );
assert( o.woCompare( p ) < 0 );
}
示例3: translateRegex
// static
void IndexBoundsBuilder::translateRegex(const RegexMatchExpression* rme,
OrderedIntervalList* oilOut, bool* exact) {
const string start = simpleRegex(rme->getString().c_str(), rme->getFlags().c_str(), exact);
// QLOG() << "regex bounds start is " << start << endl;
// Note that 'exact' is set by simpleRegex above.
if (!start.empty()) {
string end = start;
end[end.size() - 1]++;
oilOut->intervals.push_back(makeRangeInterval(start, end, true, false));
}
else {
BSONObjBuilder bob;
bob.appendMinForType("", String);
bob.appendMaxForType("", String);
BSONObj dataObj = bob.obj();
verify(dataObj.isOwned());
oilOut->intervals.push_back(makeRangeInterval(dataObj, true, false));
}
// Regexes are after strings.
BSONObjBuilder bob;
bob.appendRegex("", rme->getString(), rme->getFlags());
oilOut->intervals.push_back(makePointInterval(bob.obj()));
}
示例4: _load
bool DBConfig::_load() {
ScopedDbConnection conn( configServer.modelServer() );
BSONObj o = conn->findOne( ShardNS::database , BSON( "_id" << _name ) );
if ( o.isEmpty() ) {
conn.done();
return false;
}
unserialize( o );
BSONObjBuilder b;
b.appendRegex( "_id" , (string)"^" + _name + "." );
auto_ptr<DBClientCursor> cursor = conn->query( ShardNS::collection ,b.obj() );
assert( cursor.get() );
while ( cursor->more() ) {
BSONObj o = cursor->next();
_collections[o["_id"].String()] = CollectionInfo( o );
}
conn.done();
return true;
}
示例5: TEST
TEST( MatchExpressionParserLeafTest, NotRegex1 ) {
BSONObjBuilder b;
b.appendRegex( "$not", "abc", "i" );
BSONObj query = BSON( "x" << b.obj() );
StatusWithMatchExpression result = MatchExpressionParser::parse( query );
ASSERT_TRUE( result.isOK() );
ASSERT( !result.getValue()->matchesBSON( BSON( "x" << "abc" ) ) );
ASSERT( !result.getValue()->matchesBSON( BSON( "x" << "ABC" ) ) );
ASSERT( result.getValue()->matchesBSON( BSON( "x" << "AC" ) ) );
}
示例6: tooLargePattern
TEST( ExpressionParserArrayTest, AllBadRegexArg ) {
string tooLargePattern( 50 * 1000, 'z' );
BSONObjBuilder allArray;
allArray.appendRegex( "0", tooLargePattern, "" );
BSONObjBuilder operand;
operand.appendArray( "$all", allArray.obj() );
BSONObj query = BSON( "x" << operand.obj() );
StatusWithExpression result = ExpressionParser::parse( query );
ASSERT_FALSE( result.isOK() );
}
示例7: syncToTailOfRemoteLog
void ReplSource::syncToTailOfRemoteLog() {
string _ns = ns();
BSONObjBuilder b;
if ( !only.empty() ) {
b.appendRegex("ns", string("^") + only);
}
BSONObj last = oplogReader.findOne( _ns.c_str(), Query( b.done() ).sort( BSON( "$natural" << -1 ) ) );
if ( !last.isEmpty() ) {
BSONElement ts = last.getField( "ts" );
massert( 10386 , "non Date ts found: " + last.toString(), ts.type() == Date || ts.type() == Timestamp );
syncedTo = OpTime( ts.date() );
}
}
示例8: run
void run(){
Scope * s = globalScriptEngine->createScope();
{ // date
BSONObj o;
{
BSONObjBuilder b;
b.appendDate( "d" , 123456789 );
o = b.obj();
}
s->setObject( "x" , o );
s->invoke( "return x.d.getTime() != 12;" , BSONObj() );
ASSERT_EQUALS( true, s->getBoolean( "return" ) );
s->invoke( "z = x.d.getTime();" , BSONObj() );
ASSERT_EQUALS( 123456789 , s->getNumber( "z" ) );
s->invoke( "z = { z : x.d }" , BSONObj() );
BSONObj out = s->getObject( "z" );
ASSERT( out["z"].type() == Date );
}
{ // regex
BSONObj o;
{
BSONObjBuilder b;
b.appendRegex( "r" , "^a" , "i" );
o = b.obj();
}
s->setObject( "x" , o );
s->invoke( "z = x.r.test( 'b' );" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "z" ) );
s->invoke( "z = x.r.test( 'a' );" , BSONObj() );
ASSERT_EQUALS( true , s->getBoolean( "z" ) );
s->invoke( "z = x.r.test( 'ba' );" , BSONObj() );
ASSERT_EQUALS( false , s->getBoolean( "z" ) );
s->invoke( "z = { a : x.r };" , BSONObj() );
BSONObj out = s->getObject("z");
ASSERT_EQUALS( (string)"^a" , out["a"].regex() );
ASSERT_EQUALS( (string)"i" , out["a"].regexFlags() );
}
delete s;
}
示例9: BSON
TEST(MatchExpressionParserLeafTest, NotRegex1) {
BSONObjBuilder b;
b.appendRegex("$not", "abc", "i");
BSONObj query = BSON("x" << b.obj());
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
StatusWithMatchExpression result = MatchExpressionParser::parse(query, expCtx);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
<< "abc")));
ASSERT(!result.getValue()->matchesBSON(BSON("x"
<< "ABC")));
ASSERT(result.getValue()->matchesBSON(BSON("x"
<< "AC")));
}
示例10: BSON
TEST(MatchExpressionParserLeafTest, NotRegex1) {
BSONObjBuilder b;
b.appendRegex("$not", "abc", "i");
BSONObj query = BSON("x" << b.obj());
const CollatorInterface* collator = nullptr;
StatusWithMatchExpression result =
MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator);
ASSERT_TRUE(result.isOK());
ASSERT(!result.getValue()->matchesBSON(BSON("x"
<< "abc")));
ASSERT(!result.getValue()->matchesBSON(BSON("x"
<< "ABC")));
ASSERT(result.getValue()->matchesBSON(BSON("x"
<< "AC")));
}
示例11: getCollections
Status CatalogManagerReplicaSet::getCollections(OperationContext* txn,
const std::string* dbName,
std::vector<CollectionType>* collections,
OpTime* opTime) {
BSONObjBuilder b;
if (dbName) {
invariant(!dbName->empty());
b.appendRegex(CollectionType::fullNs(),
string(str::stream() << "^" << pcrecpp::RE::QuoteMeta(*dbName) << "\\."));
}
auto configShard = grid.shardRegistry()->getShard(txn, "config");
auto readHost = configShard->getTargeter()->findHost(kConfigReadSelector);
if (!readHost.isOK()) {
return readHost.getStatus();
}
auto findStatus = _exhaustiveFindOnConfig(readHost.getValue(),
NamespaceString(CollectionType::ConfigNS),
b.obj(),
BSONObj(),
boost::none); // no limit
if (!findStatus.isOK()) {
return findStatus.getStatus();
}
const auto& docsOpTimePair = findStatus.getValue();
for (const BSONObj& obj : docsOpTimePair.value) {
const auto collectionResult = CollectionType::fromBSON(obj);
if (!collectionResult.isOK()) {
collections->clear();
return {ErrorCodes::FailedToParse,
str::stream() << "error while parsing " << CollectionType::ConfigNS
<< " document: " << obj << " : "
<< collectionResult.getStatus().toString()};
}
collections->push_back(collectionResult.getValue());
}
if (opTime) {
*opTime = docsOpTimePair.opTime;
}
return Status::OK();
}
示例12: _checkDbDoesNotExist
Status CatalogManagerReplicaSet::_checkDbDoesNotExist(OperationContext* txn,
const string& dbName,
DatabaseType* db) {
BSONObjBuilder queryBuilder;
queryBuilder.appendRegex(
DatabaseType::name(), (string) "^" + pcrecpp::RE::QuoteMeta(dbName) + "$", "i");
const auto configShard = grid.shardRegistry()->getShard(txn, "config");
const auto readHost = configShard->getTargeter()->findHost(kConfigReadSelector);
if (!readHost.isOK()) {
return readHost.getStatus();
}
auto findStatus = _exhaustiveFindOnConfig(readHost.getValue(),
NamespaceString(DatabaseType::ConfigNS),
queryBuilder.obj(),
BSONObj(),
1);
if (!findStatus.isOK()) {
return findStatus.getStatus();
}
const auto& docs = findStatus.getValue().value;
if (docs.empty()) {
return Status::OK();
}
BSONObj dbObj = docs.front();
std::string actualDbName = dbObj[DatabaseType::name()].String();
if (actualDbName == dbName) {
if (db) {
auto parseDBStatus = DatabaseType::fromBSON(dbObj);
if (!parseDBStatus.isOK()) {
return parseDBStatus.getStatus();
}
*db = parseDBStatus.getValue();
}
return Status(ErrorCodes::NamespaceExists,
str::stream() << "database " << dbName << " already exists");
}
return Status(ErrorCodes::DatabaseDifferCase,
str::stream() << "can't have 2 databases that just differ on case "
<< " have: " << actualDbName << " want to add: " << dbName);
}
示例13: TEST
TEST( ExpressionParserArrayTest, AllRegex2 ) {
BSONObjBuilder allArray;
allArray.appendRegex( "0", "^a", "" );
allArray.append( "1", "abc" );
BSONObjBuilder all;
all.appendArray( "$all", allArray.obj() );
BSONObj query = BSON( "a" << all.obj() );
StatusWithExpression result = ExpressionParser::parse( query );
ASSERT_TRUE( result.isOK() );
BSONObj notMatchFirst = BSON( "a" << "ax" );
BSONObj matchesBoth = BSON( "a" << "abc" );
ASSERT( !result.getValue()->matchesSingleElement( notMatchFirst[ "a" ] ) );
ASSERT( result.getValue()->matchesSingleElement( matchesBoth[ "a" ] ) );
}
示例14: invariant
StatusWith<std::vector<CollectionType>> ShardingCatalogClientImpl::getCollections(
OperationContext* opCtx,
const std::string* dbName,
OpTime* opTime,
repl::ReadConcernLevel readConcernLevel) {
BSONObjBuilder b;
if (dbName) {
invariant(!dbName->empty());
b.appendRegex(CollectionType::fullNs(),
string(str::stream() << "^" << pcrecpp::RE::QuoteMeta(*dbName) << "\\."));
}
auto findStatus = _exhaustiveFindOnConfig(opCtx,
kConfigReadSelector,
readConcernLevel,
CollectionType::ConfigNS,
b.obj(),
BSONObj(),
boost::none); // no limit
if (!findStatus.isOK()) {
return findStatus.getStatus();
}
const auto& docsOpTimePair = findStatus.getValue();
std::vector<CollectionType> collections;
for (const BSONObj& obj : docsOpTimePair.value) {
const auto collectionResult = CollectionType::fromBSON(obj);
if (!collectionResult.isOK()) {
return {ErrorCodes::FailedToParse,
str::stream() << "error while parsing " << CollectionType::ConfigNS.ns()
<< " document: "
<< obj
<< " : "
<< collectionResult.getStatus().toString()};
}
collections.push_back(collectionResult.getValue());
}
if (opTime) {
*opTime = docsOpTimePair.opTime;
}
return collections;
}
示例15: is
StatusWith<std::string> CatalogManagerReplicaSet::_generateNewShardName() const {
const auto configShard = grid.shardRegistry()->getShard("config");
const auto readHost = configShard->getTargeter()->findHost(kConfigReadSelector);
if (!readHost.isOK()) {
return readHost.getStatus();
}
BSONObjBuilder shardNameRegex;
shardNameRegex.appendRegex(ShardType::name(), "^shard");
auto findStatus = grid.shardRegistry()->exhaustiveFind(readHost.getValue(),
NamespaceString(ShardType::ConfigNS),
shardNameRegex.obj(),
BSON(ShardType::name() << -1),
1);
if (!findStatus.isOK()) {
return findStatus.getStatus();
}
const auto& docs = findStatus.getValue();
int count = 0;
if (!docs.empty()) {
const auto shardStatus = ShardType::fromBSON(docs.front());
if (!shardStatus.isOK()) {
return shardStatus.getStatus();
}
std::istringstream is(shardStatus.getValue().getName().substr(5));
is >> count;
count++;
}
// TODO fix so that we can have more than 10000 automatically generated shard names
if (count < 9999) {
std::stringstream ss;
ss << "shard" << std::setfill('0') << std::setw(4) << count;
return ss.str();
}
return Status(ErrorCodes::OperationFailed, "unable to generate new shard name");
}