Status findAllChunks(const ConnectionString& configLoc, const string& ns, OwnedPointerVector<ChunkType>* chunks) { scoped_ptr<ScopedDbConnection> connPtr; scoped_ptr<DBClientCursor> cursor; try { connPtr.reset(ScopedDbConnection::getInternalScopedDbConnection(configLoc, 30)); ScopedDbConnection& conn = *connPtr; scoped_ptr<DBClientCursor> cursor(_safeCursor(conn->query(ChunkType::ConfigNS, BSON(ChunkType::ns(ns))))); while (cursor->more()) { BSONObj chunkDoc = cursor->nextSafe(); ChunkType* chunk = new ChunkType(); string errMsg; if (!chunk->parseBSON(chunkDoc, &errMsg) || !chunk->isValid(&errMsg)) { connPtr->done(); return Status(ErrorCodes::UnsupportedFormat, stream() << "invalid chunk " << chunkDoc << " read from the config server" << causedBy(errMsg)); } chunks->mutableVector().push_back(chunk); } } catch (const DBException& e) { return e.toStatus(); } connPtr->done(); return Status::OK(); }