Stream Processing Lab Manual
Stream Processing Lab Manual
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Step 9:
Step 10:
Step 1:
Step 2:
EX NO: 2
3. INSTALL MONGODB
Step 1:
Step 2:
Step 3:
app = Flask(__name__)
# Configure MongoDB
app.config["MONGO_URI"] = "mongodb://localhost:27017/myDatabase"
mongo = PyMongo(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/submit', methods=['POST'])
def submit():
fname = request.form['fname']
lname = request.form['lname']
emp_id = request.form['emp_id'] # Ensure this is unique or use MongoDB's _id
salary = request.form['salary']
if __name__ == '__main__':
app.run(debug=True)
Index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
<div>
<form action="/submit" method="POST">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname"><br><br>
<label for="emp_id">Employee ID:</label><br>
<input type="number" id="emp_id" name="emp_id"><br><br>
<label for="salary">Salary:</label><br>
Insert:
db.accounts.insertOne({
"_id": ObjectId(), // Generate a new ObjectId for _id
"accountID": 1,
"accountName": "Checking Account",
"userID": 1,
"accountType": "Checking",
"balance": 1000,
"interestRate": "0.25%",
"openingDate": ISODate("2024-03-14T00:00:00.000Z")
});
Update:
db.transactions.updateOne(
{ "_id": ObjectId("65f3e703fd04b76977bf036c") }, // Filter criteria to find the
update
{
$set: { // Specify the fields to update
"date": ISODate("2024-03-14T00:00:00.000Z"), // Update the date field
"amount": 150, // Update the amount field