WDFP Practical Ques
WDFP Practical Ques
res.end();
});
server.listen(3000, () => {
console.log('Server listening on port 3000');
});
db.students.insertMany([
{ name: "Alice", age: 25, grade: "A" },
{ name: "Bob", age: 22, grade: "B" },
{ name: "Charlie", age: 23, grade: "C" }
]);
console.log('Protocol:', protocol);
console.log('Hostname:', hostname);
console.log('Pathname:', pathname);
console.log('Query:', query);
server.listen(3000, () => {
console.log('Server listening on port 3000');
});
b) How would you find all documents in the products collection where
the price is greater than 100?
server.listen(3000, () => {
console.log('Server listening on port 3000');
});
b) update the status field to "active" for all documents in the employees
collection
// This route will be affected by both middlewares since it starts with '/api'
app.get('/api/data', (req, res) => {
res.send('Accessing protected API data with auth parameter!');
});
// This route is public and will only go through the logging middleware
app.get('/public', (req, res) => {
res.send('Accessing public data, no auth required.');
});
app.use(bodyParser.json());
app.listen(3000, () => {
console.log('Server listening on port 3000');
});
RES OBJECT
db.products.insertMany([
{ productName: "Product A", price: 19.99, category: "Electronics" },
{ productName: "Product B", price: 29.99, category: "Clothing" },
{ productName: "Product C", price: 9.99, category: "Books" }
]);
b) Write a command to update the price of a product where the productName is "Laptop"
to 1200 in the products collection.
b) Write a MongoDB command to delete all documents from the products collection
where the category is "obsolete".
db.logs.deleteMany({});
b) Write a command to remove a document from the orders collection where the
orderID is 555, if it exists.
b) Update the status field to "closed" and add a closingDate field for all documents
in the projects collection where dueDate is less than the current date.
db.projects.updateMany(
{ dueDate: { $lt: new Date() } },
{ $set: { status: "closed", closingDate: new Date() } }
);
db.products.updateOne(
{ productName: "YourProductName" },
{
$inc: { quantity: 10 },
$cond: {
if: { $gt: ["$quantity", 1000] },
then: { $remove: true },
else: {}
}
}
);
db.students.insertOne({
name: "Alice",
age: 20,
grade: "A",
subjects: ["Math", "Science"]
});
b) Insert multiple documents into the orders collection with fields orderID,
product, quantity, and status.
db.orders.insertMany([
{ orderID: 1001, product: "Laptop", quantity: 2, status: "Pending" },
{ orderID: 1002, product: "Smartphone", quantity: 1, status: "Shipped" },
{ orderID: 1003, product: "Book", quantity: 3, status: "Cancelled" }
]);