15/12/2023
// Connexion à la base de données
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";
// Création de la base de données Étudiant
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("Étudiant");
// Création de la collection Étudiants
dbo.createCollection("étudiants", function(err, res) {
if (err) throw err;
console.log("Collection étudiants créée !");
// Insertion des enregistrements dans la collection étudiants
var étudiants = [
{ nom: "JEDIDJA", âge: 25, genre: "M" },
{ nom: "Hervé", âge: 16, genre: "M" },
{ nom: "Eunice", âge: 12, genre: "F" }
];
dbo.collection("étudiants").insertMany(étudiants, function(err, res) {
if (err) throw err;
console.log("Enregistrements étudiants insérés !");
db.close();
});
});
// Création de la collection Faculté
dbo.createCollection("faculté", function(err, res) {
if (err) throw err;
console.log("Collection faculté créée !");
// Insertion des enregistrements dans la collection faculté
var faculté = [
{ nom_doyen: "Katual" },
{ secrétaire: "Rose" },
{ secrétaire: "Franck" },
{ filière: "SI" },
{ filière: "GL" },
{ filière: "IG" },
{ filière: "IA" }
];
dbo.collection("faculté").insertMany(faculté, function(err, res) {
if (err) throw err;
console.log("Enregistrements faculté insérés !");
db.close();
});
});
});