本文整理汇总了C++中BSONArrayBuilder::arrSize方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONArrayBuilder::arrSize方法的具体用法?C++ BSONArrayBuilder::arrSize怎么用?C++ BSONArrayBuilder::arrSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONArrayBuilder
的用法示例。
在下文中一共展示了BSONArrayBuilder::arrSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getErrorLabels
BSONObj getErrorLabels(const OperationSessionInfoFromClient& sessionOptions,
const std::string& commandName,
ErrorCodes::Error code,
bool hasWriteConcernError) {
BSONArrayBuilder labelArray;
// Note that we only apply the TransientTxnError label if the "autocommit" field is present in
// the session options. When present, "autocommit" will always be false, so we don't check its
// value.
if (sessionOptions.getAutocommit() &&
isTransientTransactionError(code,
hasWriteConcernError,
commandName == "commitTransaction" ||
commandName == "coordinateCommitTransaction")) {
// An error code for which isTransientTransactionError() is true indicates a transaction
// failure with no persistent side effects.
labelArray << txn::TransientTxnErrorFieldName;
}
if (ErrorCodes::isNonResumableChangeStreamError(code)) {
labelArray << "NonResumableChangeStreamError";
}
return (labelArray.arrSize() > 0) ? BSON("errorLabels" << labelArray.arr()) : BSONObj();
}
示例2: BSON
/* ****************************************************************************
*
* addTriggeredSubscriptions -
*/
static bool addTriggeredSubscriptions
(
ContextRegistration cr,
map<string, TriggeredSubscription*>& subs,
std::string& err,
std::string tenant
)
{
BSONArrayBuilder entitiesNoPatternA;
std::vector<std::string> idJsV;
std::vector<std::string> typeJsV;
for (unsigned int ix = 0; ix < cr.entityIdVector.size(); ++ix)
{
// FIXME: take into account subscriptions with no type
EntityId* enP = cr.entityIdVector[ix];
// The registration of isPattern=true entities is not supported, so we don't include them here
if (enP->isPattern == "false")
{
entitiesNoPatternA.append(BSON(CASUB_ENTITY_ID << enP->id <<
CASUB_ENTITY_TYPE << enP->type <<
CASUB_ENTITY_ISPATTERN << "false"));
idJsV.push_back(enP->id);
typeJsV.push_back(enP->type);
}
}
BSONArrayBuilder attrA;
for (unsigned int ix = 0; ix < cr.contextRegistrationAttributeVector.size(); ++ix)
{
ContextRegistrationAttribute* craP = cr.contextRegistrationAttributeVector[ix];
attrA.append(craP->name);
}
BSONObjBuilder queryNoPattern;
queryNoPattern.append(CASUB_ENTITIES, BSON("$in" << entitiesNoPatternA.arr()));
if (attrA.arrSize() > 0)
{
// If we don't do this checking, the {$in: [] } in the attribute name part will
// make the query fail
//
// queryB.append(CASUB_ATTRS, BSON("$in" << attrA.arr()));
queryNoPattern.append("$or", BSON_ARRAY(
BSON(CASUB_ATTRS << BSON("$in" << attrA.arr())) <<
BSON(CASUB_ATTRS << BSON("$size" << 0))));
}
else
{
queryNoPattern.append(CASUB_ATTRS, BSON("$size" << 0));
}
queryNoPattern.append(CASUB_EXPIRATION, BSON("$gt" << (long long) getCurrentTime()));
//
// This is JavaScript code that runs in MongoDB engine. As far as I know, this is the only
// way to do a "reverse regex" query in MongoDB (see
// http://stackoverflow.com/questions/15966991/mongodb-reverse-regex/15989520).
// Note that although we are using a isPattern=true in the MongoDB query besides $where, we
// also need to check that in the if statement in the JavaScript function given that a given
// sub document could include both isPattern=true and isPattern=false documents
//
std::string idJsString = "[ ";
for (unsigned int ix = 0; ix < idJsV.size(); ++ix)
{
if (ix != idJsV.size() - 1)
{
idJsString += "\""+idJsV[ix]+ "\" ,";
}
else
{
idJsString += "\"" +idJsV[ix]+ "\"";
}
}
idJsString += " ]";
std::string typeJsString = "[ ";
for (unsigned int ix = 0; ix < typeJsV.size(); ++ix)
{
if (ix != typeJsV.size() - 1)
{
typeJsString += "\"" +typeJsV[ix] + "\" ,";
}
else
{
typeJsString += "\"" + typeJsV[ix] + "\"";
}
}
typeJsString += " ]";
std::string function = std::string("function()") +
"{" +
//.........这里部分代码省略.........
示例3: DBException
/* ****************************************************************************
*
* associationsQuery -
*/
static bool associationsQuery
(
EntityIdVector* enV,
AttributeList* attrL,
const std::string& scope,
MetadataVector* mdV,
std::string* err,
const std::string& tenant,
int offset,
int limit,
bool details,
const std::vector<std::string>& servicePathV
)
{
DBClientBase* connection = getMongoConnection();
/* Note that SCOPE_VALUE_ASSOC_SOURCE means that the argument is a target (so we use ASSOC_TARGET_ENT and
* ASSOC_ATTRS_TARGET in the query), while SCOPE_VALUE_ASSOC_TARGET means that the argument is a source (so we
* use ASSOC_SOURCE_ENT and ASSOC_ATTRS_source in the query) */
BSONObjBuilder queryB;
/* Build query (entity part) */
BSONArrayBuilder enArray;
for (unsigned int ix = 0; ix < enV->size(); ++ix) {
enArray.append(BSON(ASSOC_ENT_ID << enV->get(ix)->id << ASSOC_ENT_TYPE << enV->get(ix)->type));
}
BSONObj queryEn;
if (scope == SCOPE_VALUE_ASSOC_SOURCE) {
queryB.append(ASSOC_TARGET_ENT, BSON("$in" << enArray.arr()));
}
else { // SCOPE_VALUE_ASSOC_TARGET
queryB.append(ASSOC_SOURCE_ENT, BSON("$in" << enArray.arr()));
}
/* Build query (attribute part) */
BSONArrayBuilder attrArray;
for (unsigned int ix = 0; ix < attrL->size() ; ++ix) {
attrArray.append(attrL->get(ix));
}
std::string attrField;
if (scope == SCOPE_VALUE_ASSOC_SOURCE) {
attrField = ASSOC_ATTRS "." ASSOC_ATTRS_TARGET;
}
else { // SCOPE_VALUE_ASSOC_TARGET
attrField = ASSOC_ATTRS "." ASSOC_ATTRS_SOURCE;
}
// If there are no attributes specified we want them all
if (attrArray.arrSize() != 0)
{
queryB.append(attrField, BSON("$in" << attrArray.arr()));
}
/* Do the query in MongoDB */
auto_ptr<DBClientCursor> cursor;
Query query(queryB.obj());
Query sortCriteria = query.sort(BSON("_id" << 1));
try
{
LM_T(LmtMongo, ("query() in '%s' collection: '%s'", getAssociationsCollectionName(tenant).c_str(), query.toString().c_str()));
mongoSemTake(__FUNCTION__, "query in AssociationsCollection");
cursor = connection->query(getAssociationsCollectionName(tenant).c_str(), query, limit, offset);
/*
* We have observed that in some cases of DB errors (e.g. the database daemon is down) instead of
* raising an exception, the query() method sets the cursor to NULL. In this case, we raise the
* exception ourselves
*/
if (cursor.get() == NULL) {
throw DBException("Null cursor from mongo (details on this is found in the source code)", 0);
}
mongoSemGive(__FUNCTION__, "query in AssociationsCollection");
LM_I(("Database Operation Successful (%s)", query.toString().c_str()));
}
catch (const DBException &e)
{
mongoSemGive(__FUNCTION__, "query in AssociationsCollection (DBException)");
*err = std::string("collection: ") + getAssociationsCollectionName(tenant).c_str() +
" - query(): " + query.toString() +
" - exception: " + e.what();
LM_E(("Database Error ('%s', '%s')", query.toString().c_str(), err->c_str()));
return false;
}
catch (...)
{
mongoSemGive(__FUNCTION__, "query in AssociationsCollection (Generic Exception)");
*err = std::string("collection: ") + getAssociationsCollectionName(tenant).c_str() +
" - query(): " + query.toString() +
" - exception: " + "generic";
LM_E(("Database Error ('%s', '%s')", query.toString().c_str(), err->c_str()));
return false;
}
//.........这里部分代码省略.........
示例4: addTriggeredSubscriptions
/* ****************************************************************************
*
* addTriggeredSubscriptions
*
*/
static bool addTriggeredSubscriptions(ContextRegistration cr,
map<string, TriggeredSubscription*>& subs,
std::string& err,
std::string tenant)
{
DBClientBase* connection = NULL;
BSONArrayBuilder entitiesNoPatternA;
std::vector<std::string> idJsV;
std::vector<std::string> typeJsV;
for (unsigned int ix = 0; ix < cr.entityIdVector.size(); ++ix ) {
//FIXME: take into account subscriptions with no type
EntityId* enP = cr.entityIdVector.get(ix);
/* The registration of isPattern=true entities is not supported, so we don't include them here */
if (enP->isPattern == "false") {
entitiesNoPatternA.append(BSON(CASUB_ENTITY_ID << enP->id << CASUB_ENTITY_TYPE << enP->type << CASUB_ENTITY_ISPATTERN << "false"));
idJsV.push_back(enP->id);
typeJsV.push_back(enP->type);
}
}
BSONArrayBuilder attrA;
for (unsigned int ix = 0; ix < cr.contextRegistrationAttributeVector.size(); ++ix) {
ContextRegistrationAttribute* craP = cr.contextRegistrationAttributeVector.get(ix);
attrA.append(craP->name);
}
BSONObjBuilder queryNoPattern;
queryNoPattern.append(CASUB_ENTITIES, BSON("$in" << entitiesNoPatternA.arr()));
if (attrA.arrSize() > 0) {
/* If we don't do this checking, the {$in: [] } in the attribute name part will
* make the query fail*/
//queryB.append(CASUB_ATTRS, BSON("$in" << attrA.arr()));
queryNoPattern.append("$or", BSON_ARRAY(
BSON(CASUB_ATTRS << BSON("$in" << attrA.arr())) <<
BSON(CASUB_ATTRS << BSON("$size" << 0))
));
}
else {
queryNoPattern.append(CASUB_ATTRS, BSON("$size" << 0));
}
queryNoPattern.append(CASUB_EXPIRATION, BSON("$gt" << (long long) getCurrentTime()));
/* This is JavaScript code that runs in MongoDB engine. As far as I know, this is the only
* way to do a "reverse regex" query in MongoDB (see
* http://stackoverflow.com/questions/15966991/mongodb-reverse-regex/15989520).
* Note that although we are using a isPattern=true in the MongoDB query besides $where, we
* also need to check that in the if statement in the JavaScript function given that a given
* sub document could include both isPattern=true and isPattern=false documents */
std::string idJsString = "[ ";
for (unsigned int ix = 0; ix < idJsV.size(); ++ix ) {
if (ix != idJsV.size()-1) {
idJsString += "\""+idJsV[ix]+ "\" ,";
}
else {
idJsString += "\"" +idJsV[ix]+ "\"";
}
}
idJsString += " ]";
std::string typeJsString = "[ ";
for (unsigned int ix = 0; ix < typeJsV.size(); ++ix ) {
if (ix != typeJsV.size()-1) {
typeJsString += "\"" +typeJsV[ix] + "\" ,";
}
else {
typeJsString += "\"" + typeJsV[ix] + "\"";
}
}
typeJsString += " ]";
std::string function = std::string("function()") +
"{" +
"enId = "+idJsString+ ";" +
"enType = "+typeJsString+ ";" +
"for (var i=0; i < this."+CASUB_ENTITIES+".length; i++) {" +
"if (this."+CASUB_ENTITIES+"[i]."+CASUB_ENTITY_ISPATTERN+" == \"true\") {" +
"for (var j=0; j < enId.length; j++) {" +
"if (enId[j].match(this."+CASUB_ENTITIES+"[i]."+CASUB_ENTITY_ID+") && this."+CASUB_ENTITIES+"[i]."+CASUB_ENTITY_TYPE+" == enType[j]) {" +
"return true; " +
"}" +
"}" +
"}" +
"}" +
"return false; " +
"}";
LM_T(LmtMongo, ("JS function: %s", function.c_str()));
std::string entPatternQ = CSUB_ENTITIES "." CSUB_ENTITY_ISPATTERN;
BSONObjBuilder queryPattern;
queryPattern.append(entPatternQ, "true");
queryPattern.append(CASUB_EXPIRATION, BSON("$gt" << (long long) getCurrentTime()));
queryPattern.appendCode("$where", function);
//.........这里部分代码省略.........