Example #1
0
    void MongoClient::saveDocument(const mongo::BSONObj &obj, const MongoNamespace &ns)
    {
        mongo::BSONElement id = obj.getField("_id");
        mongo::BSONObjBuilder builder;
        builder.append(id);
        mongo::BSONObj bsonQuery = builder.obj();
        mongo::Query query(bsonQuery);

        _dbclient->update(ns.toString(), query, obj, true, false);
        checkLastErrorAndThrow(ns.databaseName());
    }
Example #2
0
    void MongoClient::copyCollectionToDiffServer(mongo::DBClientConnection *const fromServ,const MongoNamespace &from, const MongoNamespace &to)
    {
        if (!_dbclient->exists(to.toString()))
            _dbclient->createCollection(to.toString());

        std::auto_ptr<mongo::DBClientCursor> cursor(fromServ->query(from.toString(), mongo::Query()));
        while (cursor->more()) {
            mongo::BSONObj bsonObj = cursor->next();
            _dbclient->insert(to.toString(), bsonObj);
        }
    }
Example #3
0
    void MongoClient::copyCollectionToDiffServer(mongo::DBClientBase *const fromServ, const MongoNamespace &from, const MongoNamespace &to)
    {
        if (!_dbclient->exists(to.toString()))
            _dbclient->createCollection(to.toString());

        std::unique_ptr<mongo::DBClientCursor> cursor(fromServ->query(from.toString(), mongo::Query()));

        // Cursor may be NULL, it means we have connectivity problem
        if (!cursor)
            throw mongo::DBException("Network error while attempting to run query", 0);

        while (cursor->more()) {
            mongo::BSONObj bsonObj = cursor->next();
            _dbclient->insert(to.toString(), bsonObj);
        }
    }
Example #4
0
    void MongoClient::saveDocument(const mongo::BSONObj &obj, const MongoNamespace &ns)
    {

        mongo::BSONElement id = obj.getField("_id");
        mongo::BSONObjBuilder builder;
        builder.append(id);
        mongo::BSONObj bsonQuery = builder.obj();
        mongo::Query query(bsonQuery);

        _dbclient->update(ns.toString(), query, obj, true, false);
        //_dbclient->save(ns.toString().toStdString(), obj);
    }
Example #5
0
    void MongoClient::renameCollection(const MongoNamespace &ns, const std::string &newCollectionName)
    {
        MongoNamespace from(ns);
        MongoNamespace to(ns.databaseName(), newCollectionName);

        // Building { renameCollection: <source-namespace>, to: <target-namespace> }
        mongo::BSONObjBuilder command; // { collStats: "db.collection", scale : 1 }
        command.append("renameCollection", from.toString());
        command.append("to", to.toString());

        mongo::BSONObj result;
        _dbclient->runCommand("admin", command.obj(), result); // this command should be run against "admin" db
    }
Example #6
0
    void MongoClient::duplicateCollection(const MongoNamespace &ns, const std::string &newCollectionName)
    {
        MongoNamespace from(ns);
        MongoNamespace to(ns.databaseName(), newCollectionName);

        if (!_dbclient->exists(to.toString()))
            _dbclient->createCollection(to.toString());

        std::auto_ptr<mongo::DBClientCursor> cursor(_dbclient->query(from.toString(), mongo::Query()));
        while (cursor->more()) {
            mongo::BSONObj bsonObj = cursor->next();
            _dbclient->insert(to.toString(), bsonObj);
        }
    }
Example #7
0
    void MongoClient::duplicateCollection(const MongoNamespace &ns, const std::string &newCollectionName)
    {
        MongoNamespace from(ns);
        MongoNamespace to(ns.databaseName(), newCollectionName);

        if (!_dbclient->exists(to.toString()))
            _dbclient->createCollection(to.toString());

        std::unique_ptr<mongo::DBClientCursor> cursor(_dbclient->query(from.toString(), mongo::Query()));

        // Cursor may be NULL, it means we have connectivity problem
        if (!cursor)
            throw mongo::DBException("Network error while attempting to run query", 0);

        while (cursor->more()) {
            mongo::BSONObj bsonObj = cursor->next();
            _dbclient->insert(to.toString(), bsonObj);
        }
    }
Example #8
0
 void MongoClient::removeDocuments(const MongoNamespace &ns, mongo::Query query, bool justOne /*= true*/)
 {
     _dbclient->remove(ns.toString(), query, justOne);
 }
Example #9
0
 void MongoClient::insertDocument(const mongo::BSONObj &obj, const MongoNamespace &ns)
 {
     _dbclient->insert(ns.toString(), obj);
 }
Example #10
0
 void MongoClient::dropCollection(const MongoNamespace &ns)
 {
     _dbclient->dropCollection(ns.toString());
 }
Example #11
0
 void MongoClient::createCollection(const MongoNamespace &ns)
 {
     _dbclient->createCollection(ns.toString());
 }
Example #12
0
 void MongoClient::removeDocuments(const MongoNamespace &ns, mongo::Query query, bool justOne /*= true*/)
 {
     _dbclient->remove(ns.toString(), query, justOne);
     checkLastErrorAndThrow(ns.databaseName());
 }
Example #13
0
 void MongoClient::insertDocument(const mongo::BSONObj &obj, const MongoNamespace &ns)
 {
     _dbclient->insert(ns.toString(), obj);
     checkLastErrorAndThrow(ns.databaseName());
 }