| 176 | struct GetlasterrorCmd { |
| 177 | static const char* name; |
| 178 | ACTOR static Future<Reference<ExtMsgReply>> call(Reference<ExtConnection> ec, |
| 179 | Reference<ExtMsgQuery> query, |
| 180 | Reference<ExtMsgReply> reply) { |
| 181 | state bson::BSONObjBuilder bob; |
| 182 | |
| 183 | Future<WriteResult> lastWrite = ec->lastWrite; |
| 184 | |
| 185 | bob.appendNumber("connectionId", (long long)ec->connectionId); |
| 186 | |
| 187 | try { |
| 188 | WriteResult res = wait(lastWrite); |
| 189 | bob.appendNumber("n", (long long)res.n); //< FIXME: ??? |
| 190 | bob << "err" << BSONNULL << "ok" << 1.0; |
| 191 | if (!res.upsertedOIDList.empty()) { |
| 192 | bob.appendElements(DataValue::decode_key_part(res.upsertedOIDList[0]).wrap("upserted")); |
| 193 | } |
| 194 | if (res.type == WriteType::UPDATE) { |
| 195 | bob << "updatedExisting" << (res.nModified > 0 && res.upsertedOIDList.empty()); |
| 196 | } |
| 197 | } catch (Error& e) { |
| 198 | bob.append("err", e.what()); |
| 199 | bob.append("code", e.code()); |
| 200 | bob.appendNumber("n", (long long)0); |
| 201 | bob.append("ok", 1.0); |
| 202 | } |
| 203 | |
| 204 | reply->addDocument(bob.obj()); |
| 205 | reply->setResponseFlags(8); |
| 206 | |
| 207 | ec->lastWrite = WriteResult(); |
| 208 | |
| 209 | return reply; |
| 210 | } |
| 211 | }; |
| 212 | REGISTER_CMD(GetlasterrorCmd, "getlasterror"); |
| 213 |
nothing calls this directly
no test coverage detected