0% found this document useful (0 votes)
11 views13 pages

Webx Iat2 QB Soln

The document provides an overview of various concepts related to MongoDB, Flask, and AngularJS, including data types, sharding, CRUD operations, REST APIs, URL building, cookies, file uploading, and features of frameworks. It also compares RDBMS with MongoDB, discusses user account administration, and explains AngularJS directives, data binding, filters, and dependency injection. Key examples and commands are included to illustrate the functionalities and operations within these technologies.

Uploaded by

xie.himanshu29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views13 pages

Webx Iat2 QB Soln

The document provides an overview of various concepts related to MongoDB, Flask, and AngularJS, including data types, sharding, CRUD operations, REST APIs, URL building, cookies, file uploading, and features of frameworks. It also compares RDBMS with MongoDB, discusses user account administration, and explains AngularJS directives, data binding, filters, and dependency injection. Key examples and commands are included to illustrate the functionalities and operations within these technologies.

Uploaded by

xie.himanshu29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

WEBX

1. Explain MongoDB Data Types with example

MongoDB supports a variety of data types for storing different kinds of information in documents. Here are the key
data types with examples:

String: Used for text data

name: "John Doe"

Number: For numeric values (both integers and decimals)

age: 30,

price: 99.99

Boolean: True/false values

isActive: true

Date: For storing date and time

birthDate: new Date("1990-05-15")

Array: Ordered lists of values

tags: ["mongodb", "database", "NoSQL"]

Null: For null values

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.

• Shard Router (Query Router)


A service that routes incoming database operations to the correct shard based on the shard key.

• 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

• Shard 2 stores users with IDs 3,000,001–6,000,000

• Shard 3 stores users with IDs 6,000,001–10,000,000

When a user with ID 4,000,000 logs in, the system routes the query to Shard 2 only.

3. Discuss RDBMS v/s MongoDB

RDBMS MongoDB

Uses structured tables with rows and columns. Uses collections and documents (JSON-like).

Follows a fixed schema. Schema-less (flexible structure).

Uses SQL for queries. Uses MongoDB Query Language (MQL).

Stores data in multiple related tables. Stores data in a single document (embedded).

Supports JOIN operations. No JOINs, uses embedding or referencing.

Vertical scaling (add more power to one server). Horizontal scaling via sharding.

Better for complex transactions. Better for large, unstructured data.

4. Discuss Administering User Accounts and User Roles

Administering User Accounts and User Roles

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:

• Each user has a unique username and password.

• Users are assigned roles that determine their access level.

User Roles:

• A role is a collection of permissions or privileges.

• Roles can be predefined or customized by the database administrator.

Common Roles Examples:

• Read-only: Can view data but not modify it.

• Read/Write: Can view and modify data.

• Admin: Full access including managing users and settings.

Purpose:

• Enhances security by controlling access.


• Ensures data integrity and prevents unauthorized operations.

5. Explain Accessing and Manipulating Databases commands.

Accessing and Manipulating Databases – Commands

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:

Used to switch or connect to a specific database.

• Command:

USE database_name;

Example:
USE school;
(Switches to the “school” database)

2. Creating a Database:

Used to create a new database.

• Command:

CREATE DATABASE database_name;

Example:
CREATE DATABASE library;

3. Showing Databases:

Lists all available databases.

• Command:

SHOW DATABASES;

4. Dropping a Database:

Deletes an entire database permanently.

• Command:

DROP DATABASE database_name;

Example:
DROP DATABASE testdb;

5. Creating a Table:

Defines a new table with columns.

• Command:

CREATE TABLE table_name (

column1 datatype,

column2 datatype

);
6. Updating Data:

Modifies existing data in a table.

• Command:

UPDATE table_name SET column = value WHERE condition;

6. Explain MongoDB CRUD Operations with an example

MongoDB CRUD Operations with Examples

CRUD stands for Create, Read, Update, and Delete — the four basic operations used to manage data in MongoDB.

Operation Description MongoDB Command Example

Create Adds a new document to a collection. db.students.insertOne({ name: "John", age: 20 })

Read Retrieves documents from a collection. db.students.find({ age: 20 })

Update Modifies existing document(s). db.students.updateOne({ name: "John" }, { $set: { age: 21 } })

Delete Removes document(s) from a collection. db.students.deleteOne({ name: "John" })

Explanation:

• insertOne() adds a single document to the students collection.

• find() fetches documents that match a condition.

• updateOne() changes specified fields in one document.

• deleteOne() removes the matching document from the collection.

7. Explain RSET API in detail.

REST API (Representational State Transfer Application Programming Interface)

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.

Key Concepts of REST API:

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.

Advantages of REST API:

• Platform-independent – Works across different technologies.

• Scalable and flexible – Ideal for web and mobile apps.

• Lightweight – Uses minimal bandwidth (especially with JSON).

• Easy to integrate – Widely used and supported in modern developmen

8. Discuss URL Building

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:

A typical URL consists of the following components:

protocol://domain:port/path?query#fragment

Example:

https://www.example.com:443/products/view?id=123#details

Importance of URL Building:

• Helps in accessing specific resources like pages, data entries, or API endpoints.

• Makes URLs readable and meaningful for users and search engines (SEO).

• Supports query parameters to filter, sort, or customize responses.

• Crucial for REST API calls, where each resource is accessed via a specific URL.

Best Practices for URL Building:

• Use lowercase letters and hyphens instead of spaces.

• Keep URLs short and descriptive.

• Avoid unnecessary parameters.

• Use HTTPS for secure communication.

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:

• Cookies are key-value pairs.

• They are stored on the client side.

• Flask allows you to set, read, and delete cookies easily using the request and make responsive objects.

Set Cookie Example:

@app.route('/setcookie')

def set_cookie():

resp = make_response("Cookie Set")

resp.set_cookie('username', 'John')

return resp

This sets a cookie named username with value John.

Get Cookie Example:

@app.route('/getcookie')

def get_cookie():

user = request.cookies.get('username')

return f'Hello {user}'

This reads the username cookie.

Delete Cookie Example:

@app.route('/deletecookie')

def delete_cookie():

resp = make_response("Cookie Deleted")

resp.set_cookie('username', '', expires=0)

return resp

This deletes the username cookie.

10. Explain File Uploading in Flask


File Uploading in Flask

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

o Uses POST method and enctype="multipart/form-data" to send files.

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

o Validate file type and size to prevent harmful uploads.

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)

This saves the uploaded file to the uploads/ folder.

11. What are the features of Python Flask?

Features of Python Flask

1. Lightweight and Simple:

Flask is a micro-framework, meaning it's minimal and easy to use.

2. Built-in Development Server:

Comes with a built-in server for testing and debugging.

3. Routing Support:

Allows you to define clean and readable URLs for your web pages.

4. Templating with Jinja2:

Supports dynamic HTML using Jinja2 templates.

5. RESTful Request Handling:

Supports GET, POST, PUT, DELETE methods for building REST APIs.
6. Easy to Extend:

Can be extended with plugins and third-party libraries.

7. Integrated Support for Cookies & Sessions:

Makes managing user data simple and secure.

Flask is a flexible, beginner-friendly framework ideal for small to medium web applications and REST APIs.

12. How to set, access and delete cookies in Python Flask ?

Same as Q9

13. Differentiate between Flask and Django frameworks

Flask Django

Lightweight and minimal Full-stack framework

More flexible, less built-in Includes many built-in features

Better for small projects Better for large, complex projects

Manual setup for database, auth Comes with ORM, admin panel, auth

Easier to learn and use Steeper learning curve

More control to developers More structured and opinionated

14. Explain AngularJS custom directives

AngularJS Custom Directives

Definition:

Custom directives in AngularJS allow developers to create their own HTML tags or attributes with custom behavior or
templates.

Key Components:

1. directive function – Used to define a custom directive.

2. restrict option – Defines how the directive is used (as an element, attribute, etc.).

3. template/templateUrl – Specifies the HTML content or external file.

4. link function – Handles DOM manipulation and event binding.

Purpose:

• Reuse code across components

• Add custom behavior to DOM elements


• Simplify and organize complex UI logic

Example

app.directive('myMessage', function() {

return {

template: '<h3>Hello from custom directive!</h3>'

};

});

This creates a new tag <my-message> that displays the message.

15. Explain Angular JS Data Binding

AngularJS Data Binding

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. Model: The JavaScript object holding data.

2. View: The HTML representation shown to the user.

3. Binding: Syncs the model and the view.

Types of Data Binding:

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>

Typing in the input updates the paragraph automatically.

16. Explain AngularJS filters

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:

o uppercase – Converts text to uppercase

o lowercase – Converts text to lowercase

o currency – Formats number as currency

o date – Formats date values

o orderBy – Sorts an array

o filter – Filters items in an array

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

<p>{{ price | currency }}</p>

<p>{{ name | uppercase }}</p>

These will display price as currency and name in uppercase.

17. Discus Built-in Helper Functions

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

1. Availability – Directly accessible without any import or setup.

2. Utility – Handle common tasks such as string manipulation, mathematical ops, input/output, and type
checking.

3. Efficiency – Highly optimized and reliable for performance-critical tasks.

4. Portability – Work across platforms consistently within the same language.

Example
In Python:

• len("hello") → returns 5

• int("10") → converts string to integer


• sum([1, 2, 3]) → returns 6

18. Explain AngularJS dependency injection

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.).

3. Dependencies – External objects/services required by a component (e.g., $http, $scope).

4. DI Annotation – Declaring what dependencies are needed using parameter names or $inject array (for
minification safety).

Advantages

• Promotes code reusability and separation of concerns.

• Makes unit testing easier by injecting mock dependencies.

• Reduces tight coupling between components.

Example :

app.controller('MainCtrl', function($scope, $http) {

// $http is injected into the controller

});

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:

var app = angular.module("myApp", ["ngRoute"]);

app.config(function($routeProvider) {
$routeProvider.when("/home", {

template: "<h2>Welcome to Home!</h2>"

});

});

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>

<li ng-repeat="fruit in fruits">{{ fruit }}</li>

</ul>

$scope.fruits = ["Apple", "Banana", "Orange"];

4. ng-style

Definition:
ng-style dynamically applies CSS styles to an HTML element using an expression.

Example:

<p ng-style="{'color': 'blue', 'font-size': '18px'}">Styled Text</p>

$scope.myStyle = {color: "red", "font-weight": "bold"};

-----------------------------------------------------------------------------------------------------------------------------------------------------------

You might also like