Skip to content

Instantly share code, notes, and snippets.

View kaniket7209's full-sized avatar
🎯
Focusing

kaniket7209

🎯
Focusing
View GitHub Profile
@kaniket7209
kaniket7209 / FAQ
Created December 3, 2021 19:13
Retrieving the microblog entries from MongoDB
1. How to recover data from MongoDB?
Answer: You can use read operations to retrieve data from your MongoDB database. There are multiple types of read operations that access the data in different ways. If you want to request results based on a set of criteria from the existing set of data, you can use a find operation such as the find() or findOne() methods.
2. Which method can be used to retrieve data from collection in MongoDB?
Answer: a) Switch to the test database and access the inventory collection. copy. copied. MongoDatabase mongoDB = mongoClient. ...
b) Within the connect block, set db to the test database. copy. copied. const db = client. ...
c) Switch to the test database and access the inventory collection. copy. copied. var database = client.
3. Can we retrieve data using NodeJS if yes then how?
Answer: Using Node. js to query the MongoDB data :-
@kaniket7209
kaniket7209 / FAQ
Created December 3, 2021 10:23
Storing MicroBlog entries in MongoDB
1. What is PyMongo in Python?
Answer: PyMongo is the official MongoDB Python driver for MongoDB. We recommend you use this driver to work with MongoDB from Python. If you need to access MongoDB in a non-blocking manner or from co-routines, we recommend that you use the Motor driver instead.
2. What is db in MongoDB command?
Answer: MongoDB use DATABASE_NAME is used to create database. The command will create a new database if it doesn't exist, otherwise it will return the existing database.
3. How do I run PyMongo?
Answer: Folow the below steps:
a) Create a free hosted MongoDB database using MongoDB Atlas.
b) Install PyMongo, the Python Driver.
@kaniket7209
kaniket7209 / FAQ
Created December 3, 2021 10:03
Accessing MongoDB with Compass And Atlas
1. What is MongoDB Atlas?
Answer: MongoDB Atlas is a database as a service created by the experts who design and engineer MongoDB.Atlas provides all of the features of MongoDB while automating database administration tasks such as database configuration, infrastructure provisioning, patches, scaling events, backups, and more. This allows you to deliver applications or new features quickly, and focus on what matters most to you and your customers.
2. Where is MongoDB Atlas available?
Answer: MongoDB Atlas is available across AWS, Azure, and GCP.
3. What scale does MongoDB Atlas support?
Answer: MongoDB is one of the most scalable databases on the planet, and MongoDB Atlas brings you that same scalability, but with us managing it for you:
a) You can scale up or down on larger instance types with no application downtime
b) You can scale out across multiple instances with no application downtime using MongoDB’s native sharding capabilities
@kaniket7209
kaniket7209 / FAQ
Created December 3, 2021 09:42
Introduction to MongoDB
1. What are some major drawbacks of MongoDB over SQL ?
Answer: Drawbacks are:-
a) No native JOINs. You can join manually with Python Code, But performance is much worse tham native SQL JOINs
b) Storing the key name for each filed in every document results in high memory usage.
c) There are limits to the size of the documents and amount of nesting within documents
2. What are the benefit of MongoDB?
Answer: Major Benefits are listed below:
a) More flexibity since there is no fixed schema
b) This can lead to faster development times
@kaniket7209
kaniket7209 / FAQ
Created December 3, 2021 08:42
Formatting dates correctly in our entries
1. How do I print a date in dd mm yyyy format in Python?
Answer: Follow these steps:
a) First import datetime following command-> from datetime import datetime
b) Then for today's current date you can write command as follows
now = datetime. today(). isoformat()
print(now) # '2021-12-03T11:15:55.126382'
2. How do I format a date column in Python?
Answer: Call dataframe[column] . dt. strftime(format) where dataframe[column] is the column from the DataFrame containing datetime objects and format is a string representing the new date format. Use "%m" to indicate where the month should be positioned, "%d" for the day, and "%y" for the year.
@kaniket7209
kaniket7209 / FAQ
Created December 3, 2021 07:30
Displaying past entries in the microBlog Project
1. As we know that for a python list , everytime when we restart our app , we loses everything from the list. So how can we prevent that .
Answer: We can use MongoDB
2. What does truncate() do in Python?
Answer: The truncate() method resizes the file to the given number of bytes. If the size is not specified, the current position will be used.
3. How do you truncate data in Python?
Answer: Python has two ways that remove all decimal digits from a number:
a) The math. trunc() function truncates the value of its argument to a whole number.
b) The int() function converts a number or string into an integer. During that process Python throws away the decimal part of the value.
@kaniket7209
kaniket7209 / FAQ
Created December 2, 2021 12:34
Receiving form data using Flask
1. What are the steps to receive form data using flask?
Answer: Steps are as follows:
a) The first thing is to look at the method of the form in the html page(POST/GET)
b) Put the methods as an argument inside route ex-> @app.route("/", methods=["GET", "POST"])
c) Get the content using command-> request.form.get("content")
d) Now make sure that it is the post request by placing the condition just above as-> if request.method == "POST"
e) Now simply print your content .
@kaniket7209
kaniket7209 / FAQ
Created December 2, 2021 12:01
Setting up MicroBlog Project With Flask
1. What are the steps to create a setup for simple microBlog Project ?
Answer: Follow these steps step by step:
a) Place your home.html file inside templates folder and style.css/ svg files inside static folder
b) Using pyenv switch to python version 3.9.0 using command-> pyenv local 3.9.0
c) Create your virtual environment using command-> pyenv ecec python -m venv .venv
d) Select your python interpreter by pressing F1 and select python interpreter as Python 3.9.0(.venv)
e) Activate env writing command -> source .venv/Scripts/activate
f) Install flask using command -> pip install flask
g) Now import it from flask writting command-> from flask import Flask
i) Now launch your app using render_template.Follow the below code
@kaniket7209
kaniket7209 / FAQ
Created December 2, 2021 07:39
Using loops in Jinja2
1. What happens when a template is rendered?
Answer: When a template is rendered then a template that contains variables and/or expressions is replaced with values and tags, which controls the logic of the template
2. How can we access the values from the response . Show with example
Answer: In order to access the values, one must loop through the array as shown below.
{% for market in market_prices.marketprices %}
{% for key, value in market.items() %}
{{key}}: {{value}}
{% endfor %}
{% endfor %}
@kaniket7209
kaniket7209 / FAQ
Created December 2, 2021 07:17
Conditional Statements in Jinja2
1. How do you write if condition in Jinja?
Answer: The {% if %} statement is typically used in conjunction with the {% elif %} and {% else %} statements to evaluate more than one condition
2. How do you write a for loop in Jinja2?
Answer: For loops start with {% for my_item in my_collection %} and end with {% endfor %} . This is very similar to how you'd loop over an iterable in Python.
3. How do you comment on Jinja2?
Answer: Jinja2 has no support for comments within a {{ ... }} statement. You can only use comments outside of such statements, and then only with {# .. #} or ## comment .