Class MongoServer
- Namespace
- Hi.MongoUtils
- Assembly
- HiNc.dll
A MongoDB runner that manages MongoDB processes.
public class MongoServer : IMongoRunner, IDisposable
- Inheritance
-
MongoServer
- Implements
- Inherited Members
- Extension Methods
Properties
ConnectionString
Gets the connection string to the MongoDB instance.
public string ConnectionString { get; }
Property Value
Default
Gets or sets the default MongoDB server instance. If not explicitly set, it will be automatically created.
public static MongoServer Default { get; set; }
Property Value
IsDefaultInit
Gets a value indicating whether the default MongoDB instance has been initialized.
public static bool IsDefaultInit { get; }
Property Value
Methods
CheckMongoHealth()
執行MongoDB健康檢查,確認進程存活且可響應連接
public bool CheckMongoHealth()
Returns
- bool
如果MongoDB運行正常則返回true
Dispose()
Stops the MongoDB instance and cleans up resources.
public void Dispose()
Dispose(bool)
Stops the MongoDB instance and cleans up resources.
protected virtual void Dispose(bool disposing)
Parameters
disposing
boolWhether this method is being called from Dispose().
~MongoServer()
Finalizer to ensure resources are cleaned up.
protected ~MongoServer()
GetMongoProcessId()
獲取MongoDB進程ID
public int? GetMongoProcessId()
Returns
- int?
MongoDB進程ID,如果進程不存在則返回null
IsMongoProcessRunning()
檢查MongoDB進程是否仍在運行
public bool IsMongoProcessRunning()
Returns
- bool
如果MongoDB進程仍在運行則返回true
Run(MongoRunnerOptions)
Runs a MongoDB instance with the specified options.
public static MongoServer Run(MongoRunnerOptions options = null)
Parameters
options
MongoRunnerOptionsThe MongoDB runner options.
Returns
- MongoServer
A MongoDB runner instance.
Exceptions
- TimeoutException
Thrown when connecting to MongoDB times out.