本文整理汇总了C++中Projection::includeID方法的典型用法代码示例。如果您正苦于以下问题:C++ Projection::includeID方法的具体用法?C++ Projection::includeID怎么用?C++ Projection::includeID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Projection
的用法示例。
在下文中一共展示了Projection::includeID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
virtual bool run(const string& dbname, BSONObj& cmdObj, int x, string& errmsg, BSONObjBuilder& result, bool y) {
static DBDirectClient db;
if ( cmdObj["sort"].eoo() )
return runNoDirectClient( dbname , cmdObj , x, errmsg , result, y );
string ns = dbname + '.' + cmdObj.firstElement().valuestr();
BSONObj origQuery = cmdObj.getObjectField("query"); // defaults to {}
Query q (origQuery);
BSONElement sort = cmdObj["sort"];
if (!sort.eoo())
q.sort(sort.embeddedObjectUserCheck());
bool upsert = cmdObj["upsert"].trueValue();
BSONObj fieldsHolder (cmdObj.getObjectField("fields"));
const BSONObj* fields = (fieldsHolder.isEmpty() ? NULL : &fieldsHolder);
Projection projection;
if (fields) {
projection.init(fieldsHolder);
if (!projection.includeID())
fields = NULL; // do projection in post-processing
}
BSONObj out = db.findOne(ns, q, fields);
if (out.isEmpty()) {
if (!upsert) {
result.appendNull("value");
return true;
}
BSONElement update = cmdObj["update"];
uassert(13329, "upsert mode requires update field", !update.eoo());
uassert(13330, "upsert mode requires query field", !origQuery.isEmpty());
db.update(ns, origQuery, update.embeddedObjectUserCheck(), true);
BSONObj gle = db.getLastErrorDetailed(dbname);
result.append("lastErrorObject", gle);
if (gle["err"].type() == String) {
errmsg = gle["err"].String();
return false;
}
if (cmdObj["new"].trueValue()) {
BSONElement _id = gle["upserted"];
if (_id.eoo())
_id = origQuery["_id"];
out = db.findOne(ns, QUERY("_id" << _id), fields);
}
}
else {
if (cmdObj["remove"].trueValue()) {
uassert(12515, "can't remove and update", cmdObj["update"].eoo());
db.remove(ns, QUERY("_id" << out["_id"]), 1);
BSONObj gle = db.getLastErrorDetailed(dbname);
result.append("lastErrorObject", gle);
if (gle["err"].type() == String) {
errmsg = gle["err"].String();
return false;
}
}
else { // update
BSONElement queryId = origQuery["_id"];
if (queryId.eoo() || getGtLtOp(queryId) != BSONObj::Equality) {
// need to include original query for $ positional operator
BSONObjBuilder b;
b.append(out["_id"]);
BSONObjIterator it(origQuery);
while (it.more()) {
BSONElement e = it.next();
if (strcmp(e.fieldName(), "_id"))
b.append(e);
}
q = Query(b.obj());
}
if (q.isComplex()) // update doesn't work with complex queries
q = Query(q.getFilter().getOwned());
BSONElement update = cmdObj["update"];
uassert(12516, "must specify remove or update", !update.eoo());
db.update(ns, q, update.embeddedObjectUserCheck());
BSONObj gle = db.getLastErrorDetailed(dbname);
result.append("lastErrorObject", gle);
if (gle["err"].type() == String) {
errmsg = gle["err"].String();
return false;
}
if (cmdObj["new"].trueValue())
//.........这里部分代码省略.........