Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed HW4 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
# Create your own db.py with mongodb connection details, DO NOT commit that file
# PM me on telegram your connection string, username and password
from db import db
import datetime
import db
import pymongo
db = db.rhdevsdb

date = datetime.datetime.now()
formatted_date = date.strftime("%x") + " " + date.strftime("%X")

# Create
returnResult = db.Orders.insert_one({
"orderID":"113",
"amount":"399" ,
"userID":"30",
"shopID":"13",
"status":"Completed",
"orderDate" : formatted_date
})

# Read
cursor = db.Orders.find({})
sort = ("amount", pymongo.DESCENDING)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this properly applies the sort

print(list(cursor)[5:11])

# Update
condition = datetime.datetime(2021,6,5,0,0,0)
conditional_date = condition.strftime("%x") + " " + condition.strftime("%X")
filter_con1 = { "status" : {"$in": ["Completed", "Failed"]} }
filter_con2 = { "orderDate" : {"$gte" : conditional_date}}
db.Orders.update_many({"$and" : [filter_con1, filter_con2]}, {"$set" : {"status": "Dispute"}})


# Delete
db.Orders.delete_one({"orderID": "101"})