-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
27 lines (21 loc) · 917 Bytes
/
main.py
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
"""
TITLE:
UniversalDB
DESCRIPTION:
In this example we show how to use UniversalDB with Python
"""
import universaldb as udb
if __name__ == "__main__":
# ---------- INIT
db = udb("mongodb://localhost:27017/") # use os.env variable in production!
# ---------- DB->Collection
employees = db["test"]['employees']
# ---------- ADD DOCUMENT
employees += {"name": "nikhil swami", "age": 23, "gender": "male", "salary": 10}
print(employees) # updated
# ---------- FIND DOCUMENT
print(employees[{"name": "nikhil swami"}]) # returns cursor object which is a generator, can convert to list
print(list(employees[{"age": {"$lt": 25}}])) # conditions supported just pass dict
print(employees[{"age": {"$lt": 25}}][0]) # slicing supported
# ---------- ALTERNATIVE PRINT
employees.print(limit=3, reversed=True) # with limit and reverse, new line per doc