예제 #1
0
void MongoDBTest::testBuildInfo()
{
	Poco::MongoDB::QueryRequest request("team.$cmd");
	request.setNumberToReturn(1);
	request.selector().add("buildInfo", 1);

	Poco::MongoDB::ResponseMessage response;

	try
	{
		_mongo->sendRequest(request, response);
	}
	catch(Poco::NotImplementedException& nie)
	{
		std::cout << nie.message() << std::endl;
		return;
	}

	if ( response.documents().size() > 0 )
	{
		Poco::MongoDB::Document::Ptr doc = response.documents()[0];
		std::cout << doc->toString(2);
	}
	else
	{
		fail("Didn't get a response from the buildinfo command");
	}
}
예제 #2
0
파일: SQLToMongo.cpp 프로젝트: 12307/poco
//DELETE players WHERE firstname = 'Victor'
void sample13(Poco::MongoDB::Connection& connection)
{
	std::cout << "*** SAMPLE 13 ***" << std::endl;

	Poco::MongoDB::Database db("sample");
	Poco::SharedPtr<Poco::MongoDB::DeleteRequest> request = db.createDeleteRequest("players");
	request->selector().add("firstname", "Victor");

	connection.sendRequest(*request);

	Poco::MongoDB::Document::Ptr lastError = db.getLastErrorDoc(connection);
	std::cout << "LastError: " << lastError->toString(2) << std::endl;
}
예제 #3
0
void MongoDBTest::testCommand() {
	Poco::MongoDB::Database db("team");
	Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = db.createCommand();
	command->selector().add("create", "fixCol")
		.add("capped", true)
		.add("max", 1024*1024)
		.add("size", 1024);

	Poco::MongoDB::ResponseMessage response;
	_mongo->sendRequest(*command, response);
	if ( response.documents().size() > 0 )
	{
		Poco::MongoDB::Document::Ptr doc = response.documents()[0];
	}
	else
	{
		Poco::MongoDB::Document::Ptr lastError = db.getLastErrorDoc(*_mongo);
		fail(lastError->toString(2));
	}
}
예제 #4
0
파일: SQLToMongo.cpp 프로젝트: 12307/poco
// CREATE INDEX playername
// ON players(lastname)
void sample7(Poco::MongoDB::Connection& connection)
{
	std::cout << "*** SAMPLE 7 ***" << std::endl;

	Poco::MongoDB::Database db("sample");
	Poco::MongoDB::Document::Ptr keys = new Poco::MongoDB::Document();
	keys->add("lastname", 1);
	Poco::MongoDB::Document::Ptr errorDoc = db.ensureIndex(connection, "players", "lastname", keys);

	/* Sample above is the same as the following code:
	Poco::MongoDB::Document::Ptr index = new Poco::MongoDB::Document();
	index->add("ns", "sample.players");
	index->add("name", "lastname");
	index->addNewDocument("key").add("lastname", 1);

	Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("system.indexes");
	insertRequest->documents().push_back(index);
	connection.sendRequest(*insertRequest);
	Poco::MongoDB::Document::Ptr errorDoc = db.getLastErrorDoc(connection);
	*/
	std::cout << errorDoc->toString(2);
}