Search code examples
node.jsmongodbloopbackjsstrongloop

How to connect manually to MongoDB Database in loopback?


I am trying to connect MongoDB database manually. So how is it possible to get the collection in MongoDB. I need to implement the code in custom js file and not in bootscript. If I include server.js file the problem is the entire application including the web server, boot scripts, etc, runs for the duration of the script, which means I'd have two instances of the app running.

So is there any way to manually integrate MongoDB and fetch documents in a collection.

Any help would be really appreciated.

Thanks in Advance


Solution

  • Set app variable to global and when bootscript is loaded first, set that global app variable to true and put an if condition for checking global app variable. If its set to true then return. Hope this will fix your issue.