-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdbsetup.py
More file actions
49 lines (40 loc) · 1.39 KB
/
dbsetup.py
File metadata and controls
49 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'''
Database setup for the quiz app
ONLY NEED TO RUN THIS FILE ONCE
'''
import arrow
from pymongo import MongoClient, ASCENDING
from secure import MONGO_USERNAME, MONGO_PASSWORD
from passlib.hash import pbkdf2_sha512
from uuid import uuid4
# SET UP THE CONNECTION
client = MongoClient("localhost", 27017)
db = client["aprender"] # database
thingstolearn = client["thingstolearn"] # collection
users = client["users"] # collection
client.aprender.authenticate(MONGO_USERNAME, MONGO_PASSWORD, mechanism='SCRAM-SHA-1')
print("using db {}".format(db.name))
print("using collection {}".format(db.thingstolearn.name))
someword = db.thingstolearn.find_one()
print(someword)
print("a word is {}".format(someword["word"]))
first_user = {
"first_name": "",
"last_name": "",
"username": "someusername",
"uuid": str(uuid4().urn),
"email": "emailaddress",
"password_hash": "", # put a hash here!!!
"cohort": "quizapp",
"date_created": arrow.utcnow().timestamp,
"last_login": arrow.utcnow().timestamp,
"role": "user",
"courses": []
}
db.users.insert_one(first_user)
print(db.users.find_one())
# MAKE AN INDEX ON THE "USERNAME" KEY
db.users.create_index([("username", ASCENDING)], unique=True)
# TODO uncomment for production
# MAKE AN INDEX ON THE "TOPIC" KEY
#db.thingstolearn.create_index([("topic", ASCENDING)], unique=True)