示例#1
0
        /// <summary>
        /// Returns a valid MongoDB connection string by reading needed values from ENV variables:
        /// MONGODB_HOST, MONGODB_PORT, MONGODB_USER, MONGODB_PASS
        /// </summary>
        /// <returns>A valid MongoDB connection string if all the ENV variables were set.</returns>
        private static string GetConnectionStringFromEnv()
        {
            Debug.Log("Creating connection string using ENV VARIABLES: MONGODB_HOST, MONGODB_PORT, MONGODB_USER, MONGODB_PASS");

            var url      = Environment.GetEnvironmentVariable("MONGODB_HOST");
            var port     = Environment.GetEnvironmentVariable("MONGODB_PORT");
            var username = Environment.GetEnvironmentVariable("MONGODB_USER");
            var password = Environment.GetEnvironmentVariable("MONGODB_PASS");

            return(DatabaseTools.ConnectionStringBuilder(url, port, username, password));
        }
示例#2
0
 /// <summary>
 /// Set the proper parameters to create a new connection to a MongoDB.
 /// Calling this method will reset the current connection and recreate it.
 /// Use this method if you do not want to load this parameters via ENV VARIABLES.
 /// </summary>
 /// <param name="url">Url of the database (localhost, 127.0.0.1 or the cloud server DNS).</param>
 /// <param name="port">Port that the MongoDB server is using, usually 27017.</param>
 /// <param name="username">Username to access the database.</param>
 /// <param name="password">Password to access the database.</param>
 /// <param name="databaseName">The name of the database to be created/used in the MongoDB server.</param>
 public static void SetConnectionParameters(string url = "localhost", string port = "27017", string username = "", string password = "", string databaseName = "corecms")
 {
     _databaseName     = databaseName;
     _connectionString = DatabaseTools.ConnectionStringBuilder(url, port, username, password);
     LoadNewDatabase();
 }