initial commit
This commit is contained in:
33
scripts/init-mongo.js
Normal file
33
scripts/init-mongo.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// MongoDB initialization script for Docker
|
||||
// This script runs when the MongoDB container starts for the first time
|
||||
|
||||
// Switch to the application database
|
||||
db = db.getSiblingDB('nextjs-boilerplate')
|
||||
|
||||
// Create an application user with read/write permissions
|
||||
db.createUser({
|
||||
user: 'app',
|
||||
pwd: 'apppassword',
|
||||
roles: [
|
||||
{
|
||||
role: 'readWrite',
|
||||
db: 'nextjs-boilerplate',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
// Create indexes for better performance
|
||||
db.users.createIndex({ email: 1 }, { unique: true })
|
||||
db.users.createIndex({ createdAt: 1 })
|
||||
|
||||
// Insert sample data (optional)
|
||||
db.users.insertOne({
|
||||
name: 'System Admin',
|
||||
email: 'admin@example.com',
|
||||
password: '$2a$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJgV3NI7UxrNhVbqjKUpwZAC', // hashed: admin123
|
||||
role: 'admin',
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
|
||||
console.log('Database initialized successfully')
|
||||
Reference in New Issue
Block a user