swiftmongodbmongokitten

How to initialise a mongokitten server globally in a swift file other than the main.swift file?


I use mongodb to store all data of my mac application.So I use Mongokitten library as the interface between the db and my app. Inorder to connect to db initially and maintain the connection throughout the time when application is running I need to establish a one time connection to db. But I'm not able to initialise the server globally in the swift file.What i do is connect to the server each time a operation(insertion, updation, deletion, read) is performed.This causes the connection to the server to be lost once when these operations are executed over a limit and causes my application to hang. Can anyone please help me find a solution to make the server connection only once for throughout running of application?


Solution

  • I found the answer.Implicitly unwrap the server variable and assign value to server on checking server connection. For reference follow the link :https://swiftmodules.com/planteam/mongokitten