[ps] change $db to not be global variable
[ps] move MongoDb related config into separate file
[ps] move helpers method out to separate file