// run "npm i mongodb" in the working directory. // To run this program: node tinker.js const { MongoClient } = require('mongodb'); // Replace with your MongoDB connection string const uri = "mongodb://localhost:27017"; // Database and collection names const dbName = "toyu"; const collectionName = "faculty"; async function printFaculty() { const client = new MongoClient(uri); try { // Connect to the MongoDB await client.connect(); const database = client.db(dbName); const collection = database.collection(collectionName); // Find all documents in the collection const documents = await collection.find( { "rank": "Assistant Professor" }, { "fname": 1, "lname": 1, "deptCode": 1, "_id": 0, } ).toArray(); if (documents.length > 0) { documents.forEach((doc, i) => { console.log("Faculty #" + String(i+1) + ": " + doc["fname"] + " " + doc["lname"] + ", " + doc["rank"]) }); } else { console.log(`Collection '${collectionName}' is empty.`); } } catch (error) { console.error("Error connecting to or querying MongoDB:", error); } finally { // Close the connection await client.close(); } } // Call the function to execute printFaculty();