Created
April 24, 2016 04:24
Revisions
-
alexandre created this gist
Apr 24, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ Algo que eu descobri durante um teste.... ```python from pymongo import MongoClient client = MongoClient() db = client.test_database expected_doc = { "name": "alexandre", "lang": "python3", "etc": "potato" } db["my_new_collection"].insert(doc_or_docs=expected_doc) # _id -> False to return only the original doc value try: assert db["my_new_collection"].find_one(expected_doc, {"_id": False}).keys() == expected_doc.keys() assert db["my_new_collection"].find_one(expected_doc, {"_id": False}).values() == expected_doc.values() except AssertionError: print("Fail! Now your dict items is: ") print(expected_doc.items()) ``` É...vai cair no except. Motivo: https://github.com/mongodb/mongo-python-driver/blob/master/pymongo/collection.py#L628-L675 Uma seleção um pouco mais especifica: https://github.com/mongodb/mongo-python-driver/blob/master/pymongo/collection.py#L671-L675