Created
June 18, 2019 05:54
-
-
Save shaybensasson/5d9491a53a87aafe72f933d79fbdb95b to your computer and use it in GitHub Desktop.
testing mongodb server install on ubuntu
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 characters
| import datetime | |
| DB_NAME = 'testdb' | |
| if __name__ == '__main__': | |
| import pymongo | |
| with pymongo.MongoClient("mongodb://localhost:27017/") as myclient: | |
| # mydb = myclient["mydatabase"] | |
| assert 'local' in myclient.list_database_names() | |
| if (DB_NAME in myclient.list_database_names()): | |
| myclient.drop_database(DB_NAME) | |
| mydb = myclient[DB_NAME] | |
| mycol = mydb["testcol"] | |
| mydict = {"name": "John", "address": "Highway 37", "date": datetime.datetime.now()} | |
| x = mycol.insert_one(mydict) | |
| x2 = mycol.find_one(sort=[('date', pymongo.DESCENDING)]) | |
| assert x.inserted_id == x2['_id'] | |
| myclient.drop_database(DB_NAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment