Files
dupe/mongo-init/init.js

25 lines
746 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// MongoDB başlangıç scripti: istenen veritabanını açar ve boş bir koleksiyonla başlatır
(async () => {
const dbName =
process.env.MONGO_DB ||
process.env.MONGO_INITDB_DATABASE ||
"dupe";
// Mevcut bağlantı, root kullanıcı ile admin DB üzerinden geliyor
const db = db.getSiblingDB(dbName);
const marker = "dupe_init_marker";
const collections = await db.getCollectionNames();
if (!collections.includes(marker)) {
db.createCollection(marker);
db[marker].insertOne({
createdAt: new Date(),
note: "dupe init marker"
});
print(`📦 '${dbName}' veritabanı için init marker oluşturuldu.`);
} else {
print(` '${dbName}' veritabanı zaten başlatılmış.`);
}
})();