Khởi tạo MongoDriver.
Cấu hình MongoDB driver.
import { Database, MongoDriver } from "blackcat.js-database";
const database = new Database({
driver: new MongoDriver({
mongourl: "mongodb://localhost:27017",
databaseName: "mydb",
collectionName: "store",
onLoad: ({ db, collection, databaseName }) => {
console.log(`✅ Đã kết nối với cơ sở dữ liệu: ${databaseName}`);
console.log(`📦 Bộ sưu tập: ${collection.collectionName}`);
},
onError: ({ error, databaseName }) => {
console.error(`❌ Không thể kết nối với cơ sở dữ liệu: ${databaseName}`);
console.error(error);
}
})
OptionalonCallback khi xảy ra lỗi.
OptionalonCallback khi kết nối thành công.
Driver lưu trữ dữ liệu bằng MongoDB.
⚠️ Đây không phải database chính. Class này chỉ là driver lưu trữ phụ trợ cho class
Database.Logic xử lý:
sẽ được xử lý bởi class
Database.MongoDriverchỉ chịu trách nhiệm:Toàn bộ database được lưu trong một document duy nhất.
Example