0% found this document useful (0 votes)
23 views8 pages

Ada 2

The document contains various code snippets demonstrating the use of AngularJS for a student data table and a simple calculator, as well as Node.js code for performing CRUD operations on MongoDB collections for students and employees. It includes examples for inserting, updating, deleting, and querying data in a MongoDB database. Additionally, it showcases basic HTML structures for user input and output using AngularJS bindings.

Uploaded by

pramitkanzariya
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)
23 views8 pages

Ada 2

The document contains various code snippets demonstrating the use of AngularJS for a student data table and a simple calculator, as well as Node.js code for performing CRUD operations on MongoDB collections for students and employees. It includes examples for inserting, updating, deleting, and querying data in a MongoDB database. Additionally, it showcases basic HTML structures for user input and output using AngularJS bindings.

Uploaded by

pramitkanzariya
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

2024 q1 b

<html ng-app="studentApp">

<title>Student Data Table</title>

<script src="[Link]

</head>

<body ng-controller="StudentController">

<input type="text" ng-model="searchText" placeholder="Search by Name or Age...">

<table>

<thead>

<tr>

<th>ID</th>

<th>Name</th>

<th>Age</th>

</tr>,

</thead>

<tbody>

<tr ng-repeat="student in students | filter:searchText">

<td>{{ [Link] }}</td>

<td>{{ [Link] }}</td>

<td>{{ [Link] }}</td>

</tr>

</tbody>

</table>

<script>

var app = [Link]('studentApp', []);

[Link]('StudentController', function ($scope) {

$[Link] = [
{ id: 1, name: "Alice", age: 20 },

{ id: 2, name: "Bob", age: 22 },

{ id: 3, name: "Charlie", age: 21 },

{ id: 4, name: "David", age: 23 },

{ id: 5, name: "Eve", age: 20 },

{ id: 6, name: "Frank", age: 24 },

{ id: 7, name: "Grace", age: 22 },

{ id: 8, name: "Hank", age: 21 },

{ id: 9, name: "Ivy", age: 20 },

{ id: 10, name: "Jack", age: 23 }

];

});

</script>

</body>

</html>

Write Node JS code to print values of query string variables Email and Mobile
from the following URL. CO-2 CO-3
[Link]
const express = require('express');

const app = express();

[Link]('/', (req, res) => {

// Extracting query parameters

const email = [Link];

const mobile = [Link]['Mobile'];

// Printing values to the console

[Link](`Email: ${email}`);

[Link](`Mobile: ${mobile}`);

// Sending response to the client


[Link](`Email: ${email}, Mobile: ${mobile}`);

});

// Start the server

const PORT = 8080;

[Link](PORT, () => {

[Link](`Server is running on [Link]

});

Consider a GTU database and Student Collection with fields: name, age,
course, and grades. Write code to perform insertOne() and InsertMany()
operation on Student collection using [Link] and MongoDB.

var MongoClient = require('mongodb').MongoClient;


var url = "mongodb://localhost:27017/";
var client = new MongoClient(url);
async main(){
await [Link]();
var dbo = [Link]("gtuDB");
var mydata = { name: "pramit", age: 18, course: "BE", grades: "AA" };

// Insert one document


await [Link]("students").insertOne(mydata);
[Link]("One document inserted!!!");

var mydata2 = [
{ name: "pramit", age: 18, course: "BE", grades: "AA" },
{ name: "pramit", age: 18, course: "BE", grades: "AA" }
];
// Insert multiple documents after insertOne() completes
await [Link]("students").insertMany(mydata2);
[Link]("Many documents inserted!!!")
});
});
});
main()
.then([Link])
.catch([Link])
.finally((=>[Link]());

Consider a GTU database and Student Collection with fields: name,


age, course, and grades. Write code to perform following operation
"find all students within the age range of 20 to 22" an Student
collection using [Link] and MongoDB.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

[Link](url, function (err, db) {


if (err) throw err;
var dbo = [Link]("practiceDB");

// Query to find students with age between 20 and 22


var query = { age: { $gte: 20, $lte: 22 } };

[Link]("students").find(query).toArray(function (err, result) {


if (err) throw err;

[Link]("Students aged 20-22:");


[Link](student => {
[Link](`Name: ${[Link]}, Age: ${[Link]}`);
});

[Link]();
});

Consider a GTU database and Employee Collection with fields: empid, name, Designation
and salary. Write code to perform updateOne() and updateMany() operations on
Employee Collection using [Link] and MongoDB.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

[Link](url, function(err, db) {


if (err) throw err;
var dbo = [Link]("practiceDB");

var myquery = { rollno: 6159 };


var newvalues = { $set: { rollno: 6001, name: "Jaypalji" } };

// Update one document first


[Link]("students").updateOne(myquery, newvalues, function(err, res) {
if (err) throw err;
[Link]("1 document updated");

var myquery2 = { rollno: { $gt: 6159 } };

// Update multiple documents after updateOne() completes


[Link]("students").updateMany(myquery2, newvalues, function(err, res) {
if (err) throw err;
[Link]("Many documents updated");

// **Close the database connection after all operations are completed**


[Link]();
});
});
});
Consider a GTU database and Employee Collection with fields: empid, name, Designation
and salary. Write code to perform deleteOne() and deleteMany() operations on Employee
Collection using [Link] and MongoDB.

var MongoClient = require('mongodb').MongoClient;


var url = "mongodb://localhost:27017/";

[Link](url, function(err, db) {


if (err) throw err;
var dbo = [Link]("practiceDB");

var myquery = { name: 'Jaypalji' };


var myquery2 = { rollno: { $gt: 6159 } };

// Delete one document first


[Link]("students").deleteOne(myquery, function(err, obj) {
if (err) throw err;
[Link]("1 document deleted");

// Delete multiple documents after deleteOne() completes


[Link]("students").deleteMany(myquery2, function(err, obj) {
if (err) throw err;
[Link]("Many documents deleted");
// **Properly close the database connection after all operations are done**
[Link]();
});
});
});

calculator

<html>
<head>
<script
src="[Link]
<title>Document</title>
</head>
<body>
<h1> calculator</h1>
<div ng-app="">
<p>Enter first number: <input type="number" ng-model="number1"></p>
<p>Enter second number: <input type="number" ng-model="number2"></p>
<p>Sum is: {{ number1 + number2 }}</p>
<p> minus is: {{ number1 - number2 }}</p>
<p>multiple is: {{ number1 * number2 }}</p>
<p>division is: {{ number1 / number2 }}</p>
</div>
</body>
</html>
Name dispaly
<html>
<head>
<script
src="[Link]
<title>Document</title>
</head>
<body>
<h1> calculator</h1>
<div ng-app="">
<p>Enter first name: <input type="text" ng-model="number1"></p>
<p>Enter last name: <input type="text" ng-model="number2"></p>
<p ng-bind="number1"></p>
<p ng-bind="number2"></p>
</div>
</body>
</html>

You might also like