0% found this document useful (0 votes)
16 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)
16 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
You are on page 1/ 8

2024 q1 b

<html ng-app="studentApp">

<title>Student Data Table</title>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>

</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>{{ student.id }}</td>

<td>{{ student.name }}</td>

<td>{{ student.age }}</td>

</tr>

</tbody>

</table>

<script>

var app = angular.module('studentApp', []);

app.controller('StudentController', function ($scope) {

$scope.students = [
{ 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
http://localhost:8080/[email protected]&Mobile-8877665544
const express = require('express');

const app = express();

app.get('/', (req, res) => {

// Extracting query parameters

const email = req.query.Email;

const mobile = req.query['Mobile'];

// Printing values to the console

console.log(`Email: ${email}`);

console.log(`Mobile: ${mobile}`);

// Sending response to the client


res.send(`Email: ${email}, Mobile: ${mobile}`);

});

// Start the server

const PORT = 8080;

app.listen(PORT, () => {

console.log(`Server is running on http://localhost:${PORT}`);

});

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 Node.js and MongoDB.

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


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

// Insert one document


await dbo.collection("students").insertOne(mydata);
console.log("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 dbo.collection("students").insertMany(mydata2);
console.log("Many documents inserted!!!")
});
});
});
main()
.then(console.log)
.catch(console.error)
.finally((=>client.close());

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 Node.js and MongoDB.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function (err, db) {


if (err) throw err;
var dbo = db.db("practiceDB");

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


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

dbo.collection("students").find(query).toArray(function (err, result) {


if (err) throw err;

console.log("Students aged 20-22:");


result.forEach(student => {
console.log(`Name: ${student.name}, Age: ${student.age}`);
});

db.close();
});

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 Node.js and MongoDB.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {


if (err) throw err;
var dbo = db.db("practiceDB");

var myquery = { rollno: 6159 };


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

// Update one document first


dbo.collection("students").updateOne(myquery, newvalues, function(err, res) {
if (err) throw err;
console.log("1 document updated");

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

// Update multiple documents after updateOne() completes


dbo.collection("students").updateMany(myquery2, newvalues, function(err, res) {
if (err) throw err;
console.log("Many documents updated");

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


db.close();
});
});
});
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 Node.js and MongoDB.

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


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

MongoClient.connect(url, function(err, db) {


if (err) throw err;
var dbo = db.db("practiceDB");

var myquery = { name: 'Jaypalji' };


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

// Delete one document first


dbo.collection("students").deleteOne(myquery, function(err, obj) {
if (err) throw err;
console.log("1 document deleted");

// Delete multiple documents after deleteOne() completes


dbo.collection("students").deleteMany(myquery2, function(err, obj) {
if (err) throw err;
console.log("Many documents deleted");
// **Properly close the database connection after all operations are done**
db.close();
});
});
});

calculator

<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<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="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<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