Webx Iat2 QB Soln
Webx Iat2 QB Soln
MongoDB supports a variety of data types for storing different kinds of information in documents. Here are the key
data types with examples:
age: 30,
price: 99.99
isActive: true
middleName: null
2. Explain Sharding
• Definition:
Sharding is a database partitioning technique where large datasets are divided horizontally into smaller,
faster, and more manageable segments called shards. Each shard holds a portion of the data and can be
stored on a separate server or database instance. This improves performance, scalability, and availability.
Key Components:
• Shard
A single, independent chunk of the overall dataset. Each shard contains a subset of the total data.
• Shard Key
A field (e.g., user ID, region) used to determine which shard a particular piece of data should go to. It's critical
for evenly distributing data.
• Configuration Server
Stores metadata about the cluster, such as which data ranges are on which shard. It helps the router locate
data efficiently.
Example:
Suppose you have 10 million users. To distribute load:
• Shard 1 stores users with IDs 1–3,000,000
When a user with ID 4,000,000 logs in, the system routes the query to Shard 2 only.
RDBMS MongoDB
Uses structured tables with rows and columns. Uses collections and documents (JSON-like).
Stores data in multiple related tables. Stores data in a single document (embedded).
Vertical scaling (add more power to one server). Horizontal scaling via sharding.
User account administration involves creating, managing, and securing user access in a database system. User roles
define what operations a user is allowed to perform.
User Accounts:
User Roles:
Purpose:
In database systems, various commands are used to access, create, modify, and manage databases and their data.
These commands help perform essential operations.
1. Accessing a Database:
• Command:
USE database_name;
Example:
USE school;
(Switches to the “school” database)
2. Creating a Database:
• Command:
Example:
CREATE DATABASE library;
3. Showing Databases:
• Command:
SHOW DATABASES;
4. Dropping a Database:
• Command:
Example:
DROP DATABASE testdb;
5. Creating a Table:
• Command:
column1 datatype,
column2 datatype
);
6. Updating Data:
• Command:
CRUD stands for Create, Read, Update, and Delete — the four basic operations used to manage data in MongoDB.
Explanation:
A REST API is a set of rules that allows different software applications to communicate with each other over the
internet. It follows the REST (Representational State Transfer) architecture and uses HTTP protocols for data
exchange.
1. Client-Server Architecture:
The client (like a web or mobile app) sends requests, and the server processes them and sends responses.
2. Stateless Communication:
Each API call is independent. The server does not remember previous requests from the client.
3. Uniform Interface:
REST APIs follow standard conventions, making them easy to use and understand.
4. Resource-Based:
Data is treated as resources and accessed via URLs (endpoints). Each resource (like a user, product, etc.) is
identified using a URI (Uniform Resource Identifier).
5. Data Formats:
Commonly uses JSON or XML to send and receive data.
URL Building
URL (Uniform Resource Locator) is the address used to access resources on the internet. URL building refers to the
process of constructing valid and meaningful URLs to request data from web servers or APIs.
Structure of a URL:
protocol://domain:port/path?query#fragment
Example:
https://www.example.com:443/products/view?id=123#details
• Helps in accessing specific resources like pages, data entries, or API endpoints.
• Makes URLs readable and meaningful for users and search engines (SEO).
• Crucial for REST API calls, where each resource is accessed via a specific URL.
Conclusion:
URL building is essential in web development and API integration. A well-structured URL ensures easy navigation,
effective communication with servers, and better user experience.
9. Explain Flask cookies with example
Cookies in Flask are small pieces of data stored on the client-side (browser) that allow you to maintain information
between requests. They're useful for maintaining user sessions, storing preferences, and tracking user behaviour.
Flask provides simple methods to set and retrieve cookies through its Response and Request objects.
Key Points:
• Flask allows you to set, read, and delete cookies easily using the request and make responsive objects.
@app.route('/setcookie')
def set_cookie():
resp.set_cookie('username', 'John')
return resp
@app.route('/getcookie')
def get_cookie():
user = request.cookies.get('username')
@app.route('/deletecookie')
def delete_cookie():
return resp
Definition:
File uploading in Flask refers to the process of allowing users to send files (like images or documents) from their
browser to the server, which are then handled and stored by the Flask application.
Key Components:
1. HTML Form
2. request.files
o Flask uses request.files to access the uploaded file from the client.
3. File Saving
o The uploaded file is saved to a folder (e.g., uploads/) using the save() method.
4. Security Measures
5. Configuration (Optional)
o You can set upload folder path and max file size in Flask config.
Example :
file = request.files['myfile']
file.save('uploads/' + file.filename)
3. Routing Support:
Allows you to define clean and readable URLs for your web pages.
Supports GET, POST, PUT, DELETE methods for building REST APIs.
6. Easy to Extend:
Flask is a flexible, beginner-friendly framework ideal for small to medium web applications and REST APIs.
Same as Q9
Flask Django
Manual setup for database, auth Comes with ORM, admin panel, auth
Definition:
Custom directives in AngularJS allow developers to create their own HTML tags or attributes with custom behavior or
templates.
Key Components:
2. restrict option – Defines how the directive is used (as an element, attribute, etc.).
Purpose:
Example
app.directive('myMessage', function() {
return {
};
});
Definition:
Data binding in AngularJS is the process of connecting the data (model) with the view (HTML) so that changes in one
automatically update the other.
Key Components:
1. One-way Binding :
Data flows from the model to the view only.
2. Two-way Binding:
Data flows both ways – changes in the view update the model and vice versa.
Done using ng-model directive.
Example:
<input ng-model="name">
<p>Hello {{name}}</p>
AngularJS Filters
Definition:
AngularJS filters are used to format, sort, or transform data before displaying it in the view. They work in templates
and expressions without modifying the actual data in the model.
Key Components:
1. Built-in Filters:
AngularJS provides useful built-in filters like:
2. Custom Filters:
Developers can also create custom filters for specific formatting needs.
3. Usage:
Filters are applied using the pipe symbol (|) in the HTML expression.
Example
Definition
Built-in helper functions are pre-defined functions provided by a programming language's core to perform routine
operations like data type conversion, calculations, and data handling, reducing the need for custom code.
Key Components
2. Utility – Handle common tasks such as string manipulation, mathematical ops, input/output, and type
checking.
Example
In Python:
• len("hello") → returns 5
Definition
Dependency Injection (DI) in AngularJS is a software design pattern where components (like controllers, services) are
given their dependencies from an external source rather than creating them manually. It improves modularity,
testability, and code manageability.
Key Components
1. Injector – The service responsible for instantiating components and resolving dependencies.
2. Provider – Configures and returns the service instance (can be service, factory, value, etc.).
4. DI Annotation – Declaring what dependencies are needed using parameter names or $inject array (for
minification safety).
Advantages
Example :
});
19. Explain Routing using ng-Route, ng-Repeat, ng-style, ng-view. With suitable example
Routing in AngularJS is the process of navigating between different views (pages) within a single-page application (SPA)
without reloading the entire page. It is implemented using the following components:
• ngRoute: A module that provides routing and deep linking services and directives for AngularJS apps.
• ng-view: A directive that acts as a placeholder for the content (template) of the current route.
• ng-repeat: Often used inside routed templates to display lists of data dynamically.
• ng-style: Used within routed templates to apply dynamic CSS styling based on the controller's scope.
1. ngRoute
Definition:
ngRoute is an AngularJS module that allows navigation between views (pages) in a single-page application based on
the URL.
Example:
app.config(function($routeProvider) {
$routeProvider.when("/home", {
});
});
2. ng-view
Definition:
ng-view is a directive that acts as a placeholder for the view (HTML template) matched by the current route.
Example:
<body ng-app="myApp">
<a href="#!/home">Home</a>
<div ng-view></div>
</body>
3. ng-repeat
Definition:
ng-repeat is used to loop over a collection (array or object) and display each item in the HTML.
Example:
<ul>
</ul>
4. ng-style
Definition:
ng-style dynamically applies CSS styles to an HTML element using an expression.
Example:
-----------------------------------------------------------------------------------------------------------------------------------------------------------