本文整理汇总了C++中BSONElement::_asCode方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::_asCode方法的具体用法?C++ BSONElement::_asCode怎么用?C++ BSONElement::_asCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::_asCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
JSFunction::JSFunction( string type , const BSONElement& e ) {
_type = type;
_code = e._asCode();
if ( e.type() == CodeWScope )
_wantedScope = e.codeWScopeObject();
}
示例2: run
bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
if ( !globalScriptEngine ) {
errmsg = "server-side JavaScript execution is disabled";
return false;
}
/* db.$cmd.findOne( { group : <p> } ) */
const BSONObj& p = jsobj.firstElement().embeddedObjectUserCheck();
BSONObj q;
if ( p["cond"].type() == Object )
q = p["cond"].embeddedObject();
else if ( p["condition"].type() == Object )
q = p["condition"].embeddedObject();
else
q = getQuery( p );
BSONObj key;
string keyf;
if ( p["key"].type() == Object ) {
key = p["key"].embeddedObjectUserCheck();
if ( ! p["$keyf"].eoo() ) {
errmsg = "can't have key and $keyf";
return false;
}
}
else if ( p["$keyf"].type() ) {
keyf = p["$keyf"]._asCode();
}
else {
// no key specified, will use entire object as key
}
BSONElement reduce = p["$reduce"];
if ( reduce.eoo() ) {
errmsg = "$reduce has to be set";
return false;
}
BSONElement initial = p["initial"];
if ( initial.type() != Object ) {
errmsg = "initial has to be an object";
return false;
}
string finalize;
if (p["finalize"].type())
finalize = p["finalize"]._asCode();
const string ns = parseNs(dbname, jsobj);
Client::ReadContext ctx(txn, ns);
return group( txn, ctx.ctx().db() , ns , q ,
key , keyf , reduce._asCode() , reduce.type() != CodeWScope ? 0 : reduce.codeWScopeScopeDataUnsafe() ,
initial.embeddedObject() , finalize ,
errmsg , result );
}
示例3: run
bool run(const string& dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
/* db.$cmd.findOne( { group : <p> } ) */
const BSONObj& p = jsobj.firstElement().embeddedObjectUserCheck();
BSONObj q;
if ( p["cond"].type() == Object )
q = p["cond"].embeddedObject();
else if ( p["condition"].type() == Object )
q = p["condition"].embeddedObject();
else
q = getQuery( p );
if ( p["ns"].type() != String ) {
errmsg = "ns has to be set";
return false;
}
string ns = dbname + "." + p["ns"].String();
BSONObj key;
string keyf;
if ( p["key"].type() == Object ) {
key = p["key"].embeddedObjectUserCheck();
if ( ! p["$keyf"].eoo() ) {
errmsg = "can't have key and $keyf";
return false;
}
}
else if ( p["$keyf"].type() ) {
keyf = p["$keyf"]._asCode();
}
else {
// no key specified, will use entire object as key
}
BSONElement reduce = p["$reduce"];
if ( reduce.eoo() ) {
errmsg = "$reduce has to be set";
return false;
}
BSONElement initial = p["initial"];
if ( initial.type() != Object ) {
errmsg = "initial has to be an object";
return false;
}
string finalize;
if (p["finalize"].type())
finalize = p["finalize"]._asCode();
return group( dbname , ns , q ,
key , keyf , reduce._asCode() , reduce.type() != CodeWScope ? 0 : reduce.codeWScopeScopeData() ,
initial.embeddedObject() , finalize ,
errmsg , result );
}
示例4: parseRequest
Status GroupCommand::parseRequest(const string& dbname,
const BSONObj& cmdObj,
GroupRequest* request) const {
request->ns = parseNs(dbname, cmdObj);
// By default, group requests are regular group not explain of group.
request->explain = false;
const BSONObj& p = cmdObj.firstElement().embeddedObjectUserCheck();
if (p["cond"].type() == Object) {
request->query = p["cond"].embeddedObject().getOwned();
}
else if (p["condition"].type() == Object) {
request->query = p["condition"].embeddedObject().getOwned();
}
else if (p["query"].type() == Object) {
request->query = p["query"].embeddedObject().getOwned();
}
else if (p["q"].type() == Object) {
request->query = p["q"].embeddedObject().getOwned();
}
if (p["key"].type() == Object) {
request->keyPattern = p["key"].embeddedObjectUserCheck().getOwned();
if (!p["$keyf"].eoo()) {
return Status(ErrorCodes::BadValue, "can't have key and $keyf");
}
}
else if (!p["$keyf"].eoo()) {
request->keyFunctionCode = p["$keyf"]._asCode();
}
else {
// No key specified. Use the entire object as the key.
}
BSONElement reduce = p["$reduce"];
if (reduce.eoo()) {
return Status(ErrorCodes::BadValue, "$reduce has to be set");
}
request->reduceCode = reduce._asCode();
if (reduce.type() == CodeWScope) {
request->reduceScope = reduce.codeWScopeObject().getOwned();
}
if (p["initial"].type() != Object) {
return Status(ErrorCodes::BadValue, "initial has to be an object");
}
request->initial = p["initial"].embeddedObject().getOwned();
if (!p["finalize"].eoo()) {
request->finalize = p["finalize"]._asCode();
}
return Status::OK();
}
示例5: switch
StatusWith<WhereMatchExpressionBase::WhereParams>
ExtensionsCallback::extractWhereMatchExpressionParams(BSONElement where) {
WhereMatchExpressionBase::WhereParams params;
switch (where.type()) {
case mongo::String:
case mongo::Code:
params.code = where._asCode();
params.scope = BSONObj();
break;
case mongo::CodeWScope:
params.code = where._asCode();
params.scope = where.codeWScopeObject().getOwned();
break;
default:
return {ErrorCodes::BadValue, "$where got bad type"};
}
if (params.code.empty()) {
return {ErrorCodes::BadValue, "code for $where cannot be empty"};
}
return params;
}
示例6: jsonString
//.........这里部分代码省略.........
}
s << "{ \"$binary\" : \"";
char *start = ( char * )( elem.value() ) + sizeof( int ) + 1;
base64::encode( s , start , len );
s << "\", \"$type\" : \"" << hex;
s.width( 2 );
s.fill( '0' );
s << type << dec;
s << "\" }";
break;
}
case mongo::Date:
if ( format == Strict )
s << "{ \"$date\" : ";
else
s << "ISODate(";
if( pretty ) {
Date_t d = elem.date();
long long ms = (long long) d.millis;
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
boost::posix_time::time_duration diff = boost::posix_time::millisec(ms);
boost::posix_time::ptime time = epoch + diff;
std::string timestr = miutil::isotimeString(time, true, true);
s << '"' << timestr << '"';
/* if( d == 0 ) s << '0';
else
//P s << '"' << elem.date().toString() << '"';
s << '"' << elem.date().millis << '"';*/
}
else
s << elem.date();
if ( format == Strict )
s << " }";
else
s << ")";
break;
case RegEx:
if ( format == Strict ) {
s << "{ \"$regex\" : \"" << escape( elem.regex() );
s << "\", \"$options\" : \"" << elem.regexFlags() << "\" }";
}
else {
s << "/" << escape( elem.regex() , true ) << "/";
// FIXME Worry about alpha order?
for ( const char *f = elem.regexFlags(); *f; ++f ) {
switch ( *f ) {
case 'g':
case 'i':
case 'm':
s << *f;
default:
break;
}
}
}
break;
case CodeWScope: {
BSONObj scope = elem.codeWScopeObject();
if ( ! scope.isEmpty() ) {
s << "{ \"$code\" : " << elem._asCode() << " , "
<< " \"$scope\" : " << scope.jsonString() << " }";
break;
}
}
case Code:
s << elem._asCode();
break;
case Timestamp:
if ( format == TenGen ) {
s << "Timestamp(" << ( elem.timestampTime() / 1000 ) << ", " << elem.timestampInc() << ")";
}
else {
s << "{ \"$timestamp\" : { \"t\" : " << ( elem.timestampTime() / 1000 ) << ", \"i\" : " << elem.timestampInc() << " } }";
}
break;
case MinKey:
s << "{ \"$minKey\" : 1 }";
break;
case MaxKey:
s << "{ \"$maxKey\" : 1 }";
break;
default:
StringBuilder ss;
ss << "Cannot create a properly formatted JSON string with "
<< "element: " << elem.toString() << " of type: " << elem.type();
string message = ss.str();
//massert( 10312 , message.c_str(), false );
}
return s.str();
}