{"action":"created","comment":{"url":"https://api.github.com/repos/twisted/txmongo/pulls/comments/31574295","id":31574295,"diff_hunk":"@@ -479,3 +611,50 @@ def find_and_modify(self, query=None, update=None, upsert=False, **kwargs):\n                 # Should never get here because of allowable_errors\n                 raise ValueError(\"Unexpected Error: %s\" % (result,))\n         defer.returnValue(result.get(\"value\"))\n+\n+\n+    # Distinct findAndModify utility method is needed because traditional\n+    # find_and_modify() accepts `sort` kwarg as dict and passes it to\n+    # MongoDB command without conversion. But in find_one_and_*\n+    # methods we want to take `filter.sort` instances\n+    @defer.inlineCallbacks\n+    def _new_find_and_modify(self, filter, projection, sort, upsert=None,\n+                             return_document=ReturnDocument.BEFORE, **kwargs):\n+        validate_is_mapping(\"filter\", filter)\n+        if not isinstance(return_document, bool):\n+            raise ValueError(\"return_document must be ReturnDocument.BEFORE \"\n+                             \"or ReturnDocument.AFTER\")\n+\n+        cmd = SON([(\"findAndModify\", self._collection_name),\n+                   (\"query\", filter),\n+                   (\"new\", return_document)])\n+        cmd.update(kwargs)\n+\n+        if projection is not None:\n+            cmd[\"fields\"] = self._normalize_fields_projection(projection)\n+\n+        if sort is not None:\n+            cmd[\"sort\"] = dict(sort[\"orderby\"])\n+        if upsert is not None:\n+            validate_boolean(\"upsert\", upsert)\n+            cmd[\"upsert\"] = upsert\n+\n+        no_obj_error = \"No matching object found\"\n+\n+        result = yield self._database.command(cmd, allowable_errors=[no_obj_error])\n+        defer.returnValue(result.get(\"value\"))\n+\n+    def find_one_and_delete(self, filter, projection=None, sort=None, **kwargs):","path":"txmongo/collection.py","position":260,"original_position":260,"commit_id":"965cd7452365b156b1f50c850fd10741a010dd46","original_commit_id":"965cd7452365b156b1f50c850fd10741a010dd46","user":{"login":"IlyaSkriblovsky","id":909638,"avatar_url":"https://avatars.githubusercontent.com/u/909638?v=3","gravatar_id":"","url":"https://api.github.com/users/IlyaSkriblovsky","html_url":"https://github.com/IlyaSkriblovsky","followers_url":"https://api.github.com/users/IlyaSkriblovsky/followers","following_url":"https://api.github.com/users/IlyaSkriblovsky/following{/other_user}","gists_url":"https://api.github.com/users/IlyaSkriblovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/IlyaSkriblovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IlyaSkriblovsky/subscriptions","organizations_url":"https://api.github.com/users/IlyaSkriblovsky/orgs","repos_url":"https://api.github.com/users/IlyaSkriblovsky/repos","events_url":"https://api.github.com/users/IlyaSkriblovsky/events{/privacy}","received_events_url":"https://api.github.com/users/IlyaSkriblovsky/received_events","type":"User","site_admin":false},"body":"There is a terminology clash here. TxMongo traditionally used `filter` kwarg for specifying sorting, hinting and other modifiers. But all new methods use `filter` argument to specify query and `sort` argument to specify sorting (if applicable). So we need to choose whether to be consistend with the rest of txmongo's method args or to be consistend with PyMongo. For now I choosed second option and named all args just like in PyMongo, but it might be changed if there will be objections.","created_at":"2015-06-02T21:39:21Z","updated_at":"2015-06-02T21:39:21Z","html_url":"https://github.com/twisted/txmongo/pull/115#discussion_r31574295","pull_request_url":"https://api.github.com/repos/twisted/txmongo/pulls/115","_links":{"self":{"href":"https://api.github.com/repos/twisted/txmongo/pulls/comments/31574295"},"html":{"href":"https://github.com/twisted/txmongo/pull/115#discussion_r31574295"},"pull_request":{"href":"https://api.github.com/repos/twisted/txmongo/pulls/115"}}},"pull_request":{"url":"https://api.github.com/repos/twisted/txmongo/pulls/115","id":36775967,"html_url":"https://github.com/twisted/txmongo/pull/115","diff_url":"https://github.com/twisted/txmongo/pull/115.diff","patch_url":"https://github.com/twisted/txmongo/pull/115.patch","issue_url":"https://api.github.com/repos/twisted/txmongo/issues/115","number":115,"state":"open","locked":false,"title":"New query methods","user":{"login":"IlyaSkriblovsky","id":909638,"avatar_url":"https://avatars.githubusercontent.com/u/909638?v=3","gravatar_id":"","url":"https://api.github.com/users/IlyaSkriblovsky","html_url":"https://github.com/IlyaSkriblovsky","followers_url":"https://api.github.com/users/IlyaSkriblovsky/followers","following_url":"https://api.github.com/users/IlyaSkriblovsky/following{/other_user}","gists_url":"https://api.github.com/users/IlyaSkriblovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/IlyaSkriblovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IlyaSkriblovsky/subscriptions","organizations_url":"https://api.github.com/users/IlyaSkriblovsky/orgs","repos_url":"https://api.github.com/users/IlyaSkriblovsky/repos","events_url":"https://api.github.com/users/IlyaSkriblovsky/events{/privacy}","received_events_url":"https://api.github.com/users/IlyaSkriblovsky/received_events","type":"User","site_admin":false},"body":"Implementation of new-style query methods of PyMongo 3.0:\r\n- `insert_one`, `insert_many`\r\n- `update_one`, `update_many`\r\n- `replace_one`, `replace_many`\r\n- `delete_one`, `delete_many`\r\n- `find_one_and_delete`, `find_one_and_update`, `find_one_and_replace`\r\n\r\nAll new methods (except `find_one_and_***` ones) return `pymongo.results.***Result` instances just like PyMongo's counterparts.\r\n\r\n**WARNING: This code breaks compatibility with PyMongo 2.x** by using classes which are only available in PyMongo 3.0\r\n\r\nList of what we use from PyMongo 3.0:\r\n- `pymongo.results.***Result`\r\n- `pymongo.common.validate_ok_for_update`, `pymongo.common.validate_ok_for_replace`\r\n- `pymongo.collection.ReturnDocument`\r\n\r\nAll these are just simple helper classes and functions. So we have two options:\r\n\r\n1. Drop support with PyMongo 2.x. The downside is that PyMongo 3.0 have several backward-incompatible API changes, for example, `safe=` kwarg was removed from good old CRUD methods. So if one is using both PyMongo and TxMongo in same virtualenv, she will need to modify theirs existing synchrous code which uses PyMongo.\r\n\r\n2. Keep support with PyMongo 2.x and just copy-paste listed stuff from PyMongo 3.0 into TxMongo's codebase. Not so pretty though, but works and reduces efforts needed from users to upgrade. (Btw, we already did this way for `txmongo.write_concern.WriteConcern`).\r\n\r\nWhat do you think?\r\n\r\n*Note: breaking compatibility with PyMongo 2.x have nothing to do with breaking compabitibility with MongoDB 2.x. MongoDB 2.6 is still supported by PyMongo 3.0*","created_at":"2015-06-02T21:26:15Z","updated_at":"2015-06-02T21:39:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ada4082b1de7f898efc5ca9025a8b324ef38be0d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twisted/txmongo/pulls/115/commits","review_comments_url":"https://api.github.com/repos/twisted/txmongo/pulls/115/comments","review_comment_url":"https://api.github.com/repos/twisted/txmongo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twisted/txmongo/issues/115/comments","statuses_url":"https://api.github.com/repos/twisted/txmongo/statuses/965cd7452365b156b1f50c850fd10741a010dd46","head":{"label":"IlyaSkriblovsky:new-query-methods","ref":"new-query-methods","sha":"965cd7452365b156b1f50c850fd10741a010dd46","user":{"login":"IlyaSkriblovsky","id":909638,"avatar_url":"https://avatars.githubusercontent.com/u/909638?v=3","gravatar_id":"","url":"https://api.github.com/users/IlyaSkriblovsky","html_url":"https://github.com/IlyaSkriblovsky","followers_url":"https://api.github.com/users/IlyaSkriblovsky/followers","following_url":"https://api.github.com/users/IlyaSkriblovsky/following{/other_user}","gists_url":"https://api.github.com/users/IlyaSkriblovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/IlyaSkriblovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IlyaSkriblovsky/subscriptions","organizations_url":"https://api.github.com/users/IlyaSkriblovsky/orgs","repos_url":"https://api.github.com/users/IlyaSkriblovsky/repos","events_url":"https://api.github.com/users/IlyaSkriblovsky/events{/privacy}","received_events_url":"https://api.github.com/users/IlyaSkriblovsky/received_events","type":"User","site_admin":false},"repo":{"id":31769022,"name":"txmongo","full_name":"IlyaSkriblovsky/txmongo","owner":{"login":"IlyaSkriblovsky","id":909638,"avatar_url":"https://avatars.githubusercontent.com/u/909638?v=3","gravatar_id":"","url":"https://api.github.com/users/IlyaSkriblovsky","html_url":"https://github.com/IlyaSkriblovsky","followers_url":"https://api.github.com/users/IlyaSkriblovsky/followers","following_url":"https://api.github.com/users/IlyaSkriblovsky/following{/other_user}","gists_url":"https://api.github.com/users/IlyaSkriblovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/IlyaSkriblovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IlyaSkriblovsky/subscriptions","organizations_url":"https://api.github.com/users/IlyaSkriblovsky/orgs","repos_url":"https://api.github.com/users/IlyaSkriblovsky/repos","events_url":"https://api.github.com/users/IlyaSkriblovsky/events{/privacy}","received_events_url":"https://api.github.com/users/IlyaSkriblovsky/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/IlyaSkriblovsky/txmongo","description":"asynchronous python driver for mongo","fork":true,"url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo","forks_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/forks","keys_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/teams","hooks_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/hooks","issue_events_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/issues/events{/number}","events_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/events","assignees_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/assignees{/user}","branches_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/branches{/branch}","tags_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/tags","blobs_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/git/refs{/sha}","trees_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/statuses/{sha}","languages_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/languages","stargazers_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/stargazers","contributors_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/contributors","subscribers_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/subscribers","subscription_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/subscription","commits_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/commits{/sha}","git_commits_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/git/commits{/sha}","comments_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/comments{/number}","issue_comment_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/issues/comments{/number}","contents_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/contents/{+path}","compare_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/merges","archive_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/downloads","issues_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/issues{/number}","pulls_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/pulls{/number}","milestones_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/milestones{/number}","notifications_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/labels{/name}","releases_url":"https://api.github.com/repos/IlyaSkriblovsky/txmongo/releases{/id}","created_at":"2015-03-06T12:49:23Z","updated_at":"2015-04-27T13:04:41Z","pushed_at":"2015-06-02T21:00:27Z","git_url":"git://github.com/IlyaSkriblovsky/txmongo.git","ssh_url":"git@github.com:IlyaSkriblovsky/txmongo.git","clone_url":"https://github.com/IlyaSkriblovsky/txmongo.git","svn_url":"https://github.com/IlyaSkriblovsky/txmongo","homepage":"","size":902,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"twisted:master","ref":"master","sha":"1d3e315e44d5d179da187c276c612a0584b1a319","user":{"login":"twisted","id":716546,"avatar_url":"https://avatars.githubusercontent.com/u/716546?v=3","gravatar_id":"","url":"https://api.github.com/users/twisted","html_url":"https://github.com/twisted","followers_url":"https://api.github.com/users/twisted/followers","following_url":"https://api.github.com/users/twisted/following{/other_user}","gists_url":"https://api.github.com/users/twisted/gists{/gist_id}","starred_url":"https://api.github.com/users/twisted/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twisted/subscriptions","organizations_url":"https://api.github.com/users/twisted/orgs","repos_url":"https://api.github.com/users/twisted/repos","events_url":"https://api.github.com/users/twisted/events{/privacy}","received_events_url":"https://api.github.com/users/twisted/received_events","type":"Organization","site_admin":false},"repo":{"id":318058,"name":"txmongo","full_name":"twisted/txmongo","owner":{"login":"twisted","id":716546,"avatar_url":"https://avatars.githubusercontent.com/u/716546?v=3","gravatar_id":"","url":"https://api.github.com/users/twisted","html_url":"https://github.com/twisted","followers_url":"https://api.github.com/users/twisted/followers","following_url":"https://api.github.com/users/twisted/following{/other_user}","gists_url":"https://api.github.com/users/twisted/gists{/gist_id}","starred_url":"https://api.github.com/users/twisted/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twisted/subscriptions","organizations_url":"https://api.github.com/users/twisted/orgs","repos_url":"https://api.github.com/users/twisted/repos","events_url":"https://api.github.com/users/twisted/events{/privacy}","received_events_url":"https://api.github.com/users/twisted/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twisted/txmongo","description":"asynchronous python driver for mongo","fork":false,"url":"https://api.github.com/repos/twisted/txmongo","forks_url":"https://api.github.com/repos/twisted/txmongo/forks","keys_url":"https://api.github.com/repos/twisted/txmongo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twisted/txmongo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twisted/txmongo/teams","hooks_url":"https://api.github.com/repos/twisted/txmongo/hooks","issue_events_url":"https://api.github.com/repos/twisted/txmongo/issues/events{/number}","events_url":"https://api.github.com/repos/twisted/txmongo/events","assignees_url":"https://api.github.com/repos/twisted/txmongo/assignees{/user}","branches_url":"https://api.github.com/repos/twisted/txmongo/branches{/branch}","tags_url":"https://api.github.com/repos/twisted/txmongo/tags","blobs_url":"https://api.github.com/repos/twisted/txmongo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twisted/txmongo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twisted/txmongo/git/refs{/sha}","trees_url":"https://api.github.com/repos/twisted/txmongo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twisted/txmongo/statuses/{sha}","languages_url":"https://api.github.com/repos/twisted/txmongo/languages","stargazers_url":"https://api.github.com/repos/twisted/txmongo/stargazers","contributors_url":"https://api.github.com/repos/twisted/txmongo/contributors","subscribers_url":"https://api.github.com/repos/twisted/txmongo/subscribers","subscription_url":"https://api.github.com/repos/twisted/txmongo/subscription","commits_url":"https://api.github.com/repos/twisted/txmongo/commits{/sha}","git_commits_url":"https://api.github.com/repos/twisted/txmongo/git/commits{/sha}","comments_url":"https://api.github.com/repos/twisted/txmongo/comments{/number}","issue_comment_url":"https://api.github.com/repos/twisted/txmongo/issues/comments{/number}","contents_url":"https://api.github.com/repos/twisted/txmongo/contents/{+path}","compare_url":"https://api.github.com/repos/twisted/txmongo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twisted/txmongo/merges","archive_url":"https://api.github.com/repos/twisted/txmongo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twisted/txmongo/downloads","issues_url":"https://api.github.com/repos/twisted/txmongo/issues{/number}","pulls_url":"https://api.github.com/repos/twisted/txmongo/pulls{/number}","milestones_url":"https://api.github.com/repos/twisted/txmongo/milestones{/number}","notifications_url":"https://api.github.com/repos/twisted/txmongo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twisted/txmongo/labels{/name}","releases_url":"https://api.github.com/repos/twisted/txmongo/releases{/id}","created_at":"2009-09-26T06:00:05Z","updated_at":"2015-05-17T01:17:10Z","pushed_at":"2015-06-02T21:26:15Z","git_url":"git://github.com/twisted/txmongo.git","ssh_url":"git@github.com:twisted/txmongo.git","clone_url":"https://github.com/twisted/txmongo.git","svn_url":"https://github.com/twisted/txmongo","homepage":"","size":1308,"stargazers_count":256,"watchers_count":256,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":62,"mirror_url":null,"open_issues_count":6,"forks":62,"open_issues":6,"watchers":256,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twisted/txmongo/pulls/115"},"html":{"href":"https://github.com/twisted/txmongo/pull/115"},"issue":{"href":"https://api.github.com/repos/twisted/txmongo/issues/115"},"comments":{"href":"https://api.github.com/repos/twisted/txmongo/issues/115/comments"},"review_comments":{"href":"https://api.github.com/repos/twisted/txmongo/pulls/115/comments"},"review_comment":{"href":"https://api.github.com/repos/twisted/txmongo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twisted/txmongo/pulls/115/commits"},"statuses":{"href":"https://api.github.com/repos/twisted/txmongo/statuses/965cd7452365b156b1f50c850fd10741a010dd46"}}}}