@@ -38,12 +38,12 @@ func ConnectDb(config *MongodbConfig) {
3838 client , err = mongo .Connect (ctx , clientOpts )
3939
4040 if err != nil {
41- log .Fatalf ("❌ Failed to connect to MongoDB: %v" , err )
41+ log .Printf ("❌ Failed to connect to MongoDB: %v" , err )
4242 }
4343
4444 // Verify connection
4545 if err := client .Ping (ctx , nil ); err != nil {
46- log .Fatalf ("❌ Failed to ping MongoDB: %v" , err )
46+ log .Printf ("❌ Failed to ping MongoDB: %v" , err )
4747 }
4848
4949 log .Printf ("✅ Connected to MongoDB on port: %s" , config .Port )
@@ -59,7 +59,7 @@ func CreateCollection(dbName string, collectionName string) {
5959 log .Printf ("List of Collections in %s: %v" , dbName , existingCollections )
6060
6161 if err != nil {
62- log .Fatalf ("❌ Failed to list collections in DB %s: %v" , dbName , err )
62+ log .Printf ("❌ Failed to list collections in DB %s: %v" , dbName , err )
6363 }
6464
6565 existingMap := make (map [string ]bool )
@@ -71,7 +71,7 @@ func CreateCollection(dbName string, collectionName string) {
7171 // Create only missing collections
7272 if ! existingMap [collectionName ] {
7373 if err := GetDb (dbName ).CreateCollection (ctx , collectionName ); err != nil {
74- log .Fatalf ("❌ Failed to create collection %s: %v" , collectionName , err )
74+ log .Printf ("❌ Failed to create collection %s: %v" , collectionName , err )
7575 }
7676
7777 log .Printf ("✅ Created collection: %s" , collectionName )
@@ -92,7 +92,7 @@ func CreateCollections(dbName string, collections []string) {
9292 log .Printf ("List of Collections: %s" , existingCollections )
9393
9494 if err != nil {
95- log .Fatalf ("Failed to list collections in DB %s: %v" , dbName , err )
95+ log .Printf ("Failed to list collections in DB %s: %v" , dbName , err )
9696 }
9797
9898 existingMap := make (map [string ]bool )
@@ -107,7 +107,7 @@ func CreateCollections(dbName string, collections []string) {
107107 for _ , collection := range collections {
108108 if ! existingMap [collection ] {
109109 if err := db .CreateCollection (ctx , collection ); err != nil {
110- log .Fatalf ("Failed to create collection %s: %v" , collection , err )
110+ log .Printf ("Failed to create collection %s: %v" , collection , err )
111111 }
112112
113113 log .Printf ("Created collection: %s" , collection )
@@ -122,8 +122,8 @@ func CreateIndex(dbName string, collectionName string, indexModel mongo.IndexMod
122122 _ , err := GetDb (dbName ).Collection (collectionName ).Indexes ().CreateOne (ctx , indexModel )
123123
124124 if err != nil {
125- log .Fatalf ("❌ Failed to create index for collection: %s in db: %s" , collectionName , dbName )
126- log .Fatalf ("❌ Error while creating creating index: %v" , err )
125+ log .Printf ("❌ Failed to create index for collection: %s in db: %s" , collectionName , dbName )
126+ log .Printf ("❌ Error while creating creating index: %v" , err )
127127 } else {
128128 log .Println ("✅ Index Created Successfully" )
129129 }
@@ -141,8 +141,8 @@ func CreateUniqueIndex(dbName string, collectionName string, field string) {
141141 _ , err := GetDb (dbName ).Collection (collectionName ).Indexes ().CreateOne (ctx , indexModel )
142142
143143 if err != nil {
144- log .Fatalf ("❌ Failed to create index for collection: %s in db: %s" , collectionName , dbName )
145- log .Fatalf ("❌ Error while creating creating index: %v" , err )
144+ log .Printf ("❌ Failed to create index for collection: %s in db: %s" , collectionName , dbName )
145+ log .Printf ("❌ Error while creating creating index: %v" , err )
146146 } else {
147147 log .Println ("✅ Index Created Successfully" )
148148 }
0 commit comments