本文整理汇总了C++中BSONObjBuilder::genOID方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObjBuilder::genOID方法的具体用法?C++ BSONObjBuilder::genOID怎么用?C++ BSONObjBuilder::genOID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObjBuilder
的用法示例。
在下文中一共展示了BSONObjBuilder::genOID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeToDB
/**********************************************************
*similar to writetodb in FileRec
*
***********************************************************/
void VersionRec::writeToDB(mongo::DBClientConnection& conn) {
BSONObjBuilder record;
if (this->versionid.empty()) { //if no id has been read in because it is a new version
record.genOID();//create one
} else {
mongo::OID theoid(this->versionid); //use current id
record.append("_id", theoid);
}
//convert to BSON
record.append("Tempname", this->tmpname);
record.append("filehash", this->filehash);
record.append("length", this->length);
record.append("Version", this->versionnumber);
/* love you */ long long time = this->modifytime.tv_nsec;
record.append("Mtnsec", time);
time = this->modifytime.tv_sec;
record.append("mtsec", time);
mongo::BSONArrayBuilder Version;
for (vector<VersionDiffBlock>::iterator it = changes.begin(); it != changes.end(); ++it) {
BSONObjBuilder version;
version.append("Blknum", (*it).blockNo);
version.append("hash", (*it).blockHash);
Version.append(version.obj());
}
record.append("Blktable", Version.arr());
BSONObj result = record.obj();
if (this->versionid.empty()) {
mongo::BSONElement thing;
result.getObjectID(thing);
mongo::OID anoid = thing.OID();
this->versionid = anoid.toString();
}
auto_ptr<mongo::DBClientCursor> cursor = conn.query("fileRecords.FileVersion", MONGO_QUERY("_id" << mongo::OID(this->versionid)));
if (cursor->more()) {//already a version with same id, update
conn.update("fileRecords.FileVersion", MONGO_QUERY("_id" << mongo::OID(this->versionid)), result);
} else { //new version
conn.insert("fileRecords.FileVersion", result);
}
string e = conn.getLastError();
if (!e.empty()) {
cout << "something failed failed: " << e << std::endl;
sleep(1);
exit(1);
}
else{
cout << "Version " << this->versionnumber << " successfully written to database" << endl;
}
}
示例2: run
void run() {
{
BSONObjBuilder b;
b.genOID();
b.append("files_id", 0);
b.append("n", 0);
b.appendBinDataArrayDeprecated("data", "hello ", 6);
db.insert(ns(), b.obj());
}
{
BSONObjBuilder b;
b.genOID();
b.append("files_id", 0);
b.append("n", 1);
b.appendBinDataArrayDeprecated("data", "world", 5);
db.insert(ns(), b.obj());
}
BSONObj result;
ASSERT( db.runCommand("test", BSON("filemd5" << 0), result) );
ASSERT_EQUALS( string("5eb63bbbe01eeed093cb22bb8f5acdc3") , result["md5"].valuestr() );
}
示例3: run
void run() {
ASSERT( db.createCollection(ns()) );
{
BSONObjBuilder b;
b.genOID();
b.append("name", "Tom");
b.append("rating", 0);
db.insert(ns(), b.obj());
}
BSONObjBuilder cmd;
cmd.appendSymbol("findAndModify", nsColl()); // Use Symbol for SERVER-16260
cmd.append("update", BSON("$inc" << BSON("score" << 1)) );
cmd.append("new", true);
BSONObj result;
bool ok = db.runCommand(nsDb(), cmd.obj(), result);
log() << result.jsonString();
ASSERT(ok);
// TODO(kangas) test that Tom's score is 1
}