// MongoDB initialization script db = db.getSiblingDB('ryp'); // Create collections with validation db.createCollection('users', { validator: { $jsonSchema: { bsonType: 'object', required: ['email', 'passwordHash', 'displayName', 'createdAt'], properties: { email: { bsonType: 'string', pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' }, passwordHash: { bsonType: 'string', minLength: 60, maxLength: 60 }, displayName: { bsonType: 'string', minLength: 1, maxLength: 50 }, createdAt: { bsonType: 'date' }, currentStreak: { bsonType: 'int', minimum: 0 }, longestStreak: { bsonType: 'int', minimum: 0 } } } } }); // Create indexes for better performance db.users.createIndex({ email: 1 }, { unique: true }); db.users.createIndex({ createdAt: 1 }); db.users.createIndex({ currentStreak: -1 }); // Create application user (optional - for development) if (db.getName() === 'ryp') { db.createUser({ user: 'ryp_user', pwd: 'ryp_password', roles: [ { role: 'readWrite', db: 'ryp' } ] }); } print('Database initialized successfully');