diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-07-10 16:52:49 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-07-26 15:13:34 -0400 |
commit | c731446ad3cc399d33b5b2cb28e5b776580f1beb (patch) | |
tree | 13be492fa9b16ed3d9e296d4d42e9fa2598cfad4 /src/mongo/client/dbclient.cpp | |
parent | 191931c4390ab1ede373e6772aa4d3999518fdaf (diff) | |
download | mongo-c731446ad3cc399d33b5b2cb28e5b776580f1beb.tar.gz |
SERVER-28509 Make DBClient use write commands
Everything that needs to actually use legacy write ops now does so explicitly.
Diffstat (limited to 'src/mongo/client/dbclient.cpp')
-rw-r--r-- | src/mongo/client/dbclient.cpp | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp index 95b66f88c2d..5f3c4760094 100644 --- a/src/mongo/client/dbclient.cpp +++ b/src/mongo/client/dbclient.cpp @@ -1057,33 +1057,49 @@ unsigned long long DBClientConnection::query(stdx::function<void(DBClientCursorB } void DBClientBase::insert(const string& ns, BSONObj obj, int flags) { - auto msg = makeInsertMessage(ns, obj, flags); - say(msg); + insert(ns, std::vector<BSONObj>{obj}, flags); } -// TODO: Merge with other insert implementation? void DBClientBase::insert(const string& ns, const vector<BSONObj>& v, int flags) { - auto msg = makeInsertMessage(ns, v.data(), v.size(), flags); - say(msg); + bool ordered = !(flags & InsertOption_ContinueOnError); + auto nss = NamespaceString(ns); + auto request = + OpMsgRequest::fromDBAndBody(nss.db(), BSON("insert" << nss.coll() << "ordered" << ordered)); + request.sequences.push_back({"documents", v}); + + // Ignoring reply to match fire-and-forget OP_INSERT behavior. + runCommand(std::move(request)); } void DBClientBase::remove(const string& ns, Query obj, int flags) { - auto msg = makeRemoveMessage(ns, obj.obj, flags); - say(msg); + int limit = (flags & RemoveOption_JustOne) ? 1 : 0; + auto nss = NamespaceString(ns); + + auto request = OpMsgRequest::fromDBAndBody(nss.db(), BSON("delete" << nss.coll())); + request.sequences.push_back({"deletes", {BSON("q" << obj.obj << "limit" << limit)}}); + + // Ignoring reply to match fire-and-forget OP_REMOVE behavior. + runCommand(std::move(request)); } void DBClientBase::update(const string& ns, Query query, BSONObj obj, bool upsert, bool multi) { - int flags = 0; - if (upsert) - flags |= UpdateOption_Upsert; - if (multi) - flags |= UpdateOption_Multi; - update(ns, query, obj, flags); + auto nss = NamespaceString(ns); + + auto request = OpMsgRequest::fromDBAndBody(nss.db(), BSON("update" << nss.coll())); + request.sequences.push_back( + {"updates", + {BSON("q" << query.obj << "u" << obj << "upsert" << upsert << "multi" << multi)}}); + + // Ignoring reply to match fire-and-forget OP_UPDATE behavior. + runCommand(std::move(request)); } void DBClientBase::update(const string& ns, Query query, BSONObj obj, int flags) { - auto msg = makeUpdateMessage(ns, query.obj, obj, flags); - say(msg); + update(ns, + std::move(query), + std::move(obj), + flags & UpdateOption_Upsert, + flags & UpdateOption_Multi); } void DBClientBase::killCursor(long long cursorId) { |