better daemonize function with reference from MongoDB