@@ -150,7 +150,7 @@ namespace
150150 std::string clientFirstMsg = Poco::format (" n=%s,r=%s" , username, clientNonce);
151151
152152 Poco::SharedPtr<OpMsgMessage> pCommand = db.createOpMsgMessage (" $cmd" );
153- pCommand->setCommandName (" saslStart " );
153+ pCommand->setCommandName (OpMsgMessage:: CMD_SASL_START );
154154 pCommand->body ()
155155 .add <std::string>(" mechanism" , mechanism)
156156 .add <Binary::Ptr>(" payload" , new Binary (Poco::format (" n,,%s" , clientFirstMsg)))
@@ -214,7 +214,7 @@ namespace
214214 std::string clientFinal = Poco::format (" %s,p=%s" , clientFinalNoProof, encodeBase64 (clientProof));
215215
216216 pCommand = db.createOpMsgMessage (" $cmd" );
217- pCommand->setCommandName (" saslContinue " );
217+ pCommand->setCommandName (OpMsgMessage:: CMD_SASL_CONTINUE );
218218 pCommand->body ()
219219 .add <Poco::Int32>(" conversationId" , conversationId)
220220 .add <Binary::Ptr>(" payload" , new Binary (clientFinal));
@@ -247,14 +247,25 @@ namespace
247247 throw Poco::ProtocolException (" server signature verification failed" );
248248
249249 pCommand = db.createOpMsgMessage (" $cmd" );
250- pCommand->setCommandName (" saslContinue " );
250+ pCommand->setCommandName (OpMsgMessage:: CMD_SASL_CONTINUE );
251251 pCommand->body ()
252252 .add <Poco::Int32>(" conversationId" , conversationId)
253253 .add <Binary::Ptr>(" payload" , new Binary);
254254
255255 connection.sendRequest (*pCommand, response);
256256 return response.responseOk ();
257257 }
258+
259+
260+ Document::Ptr keysFromIndexedFields (const Database::IndexedFields& indexedFields)
261+ {
262+ Document::Ptr keys = new Document ();
263+ for (const auto & [name, ascending]: indexedFields)
264+ {
265+ keys->add (name, ascending ? 1 : -1 );
266+ }
267+ return keys;
268+ }
258269} // namespace
259270
260271
@@ -407,11 +418,7 @@ Poco::MongoDB::Document::Ptr Database::createIndex(
407418{
408419// https://www.mongodb.com/docs/manual/reference/command/createIndexes/
409420
410- MongoDB::Document::Ptr keys = new MongoDB::Document ();
411-
412- for (const auto & [name, ascending]: indexedFields) {
413- keys->add (name, ascending ? 1 : -1 );
414- }
421+ MongoDB::Document::Ptr keys = keysFromIndexedFields (indexedFields);
415422
416423 MongoDB::Document::Ptr index = new MongoDB::Document ();
417424 index->add (" key" s, keys);
@@ -467,4 +474,48 @@ Poco::MongoDB::Document::Ptr Database::createIndex(
467474}
468475
469476
477+ Poco::MongoDB::Document::Ptr Database::dropIndex (
478+ Connection& connection,
479+ const std::string& collection,
480+ const std::string& indexName)
481+ {
482+ // https://www.mongodb.com/docs/manual/reference/command/dropIndexes/
483+
484+ auto request = createOpMsgMessage (collection);
485+ request->setCommandName (OpMsgMessage::CMD_DROP_INDEXES );
486+ request->body ().add (" index" s, indexName);
487+
488+ OpMsgMessage response;
489+ connection.sendRequest (*request, response);
490+
491+ return new MongoDB::Document (response.body ());
492+ }
493+
494+
495+ Poco::MongoDB::Document::Ptr Database::dropIndex (
496+ Connection& connection,
497+ const std::string& collection,
498+ const IndexedFields& indexedFields)
499+ {
500+ // https://www.mongodb.com/docs/manual/reference/command/dropIndexes/
501+
502+ auto request = createOpMsgMessage (collection);
503+ request->setCommandName (OpMsgMessage::CMD_DROP_INDEXES );
504+ request->body ().add (" index" s, keysFromIndexedFields (indexedFields));
505+
506+ OpMsgMessage response;
507+ connection.sendRequest (*request, response);
508+
509+ return new MongoDB::Document (response.body ());
510+ }
511+
512+
513+ Poco::MongoDB::Document::Ptr Database::dropAllIndexes (
514+ Connection& connection,
515+ const std::string& collection)
516+ {
517+ return dropIndex (connection, collection, " *" s);
518+ }
519+
520+
470521} // namespace Poco::MongoDB
0 commit comments