Exemplo n.º 1
0
/**********************************************************
 *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;
    }
}
Exemplo n.º 2
0
            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() );
            }
Exemplo n.º 3
0
        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
        }