23 lines
709 B
C#
23 lines
709 B
C#
using MongoDB.Bson;
|
|||
|
|
using MongoDB.Driver;
|
||
|
|
|
||
|
|
namespace PrivaPub.Infrastructure.Data
|
||
|
|
{
|
||
|
|
// Whether the mongod is a replica set member (production's is a one-member set, rs0): only then can a read session
|
||
|
|
// hold one point in time across collections (a snapshot), which a backup needs to be consistent.
|
||
|
|
public static class MongoTopology
|
||
|
|
{
|
||
|
|
public static async Task<bool> IsReplicaSet(IMongoDatabase database, CancellationToken token)
|
||
|
|
{
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var hello = await database.Client.GetDatabase("admin").RunCommandAsync<BsonDocument>(new BsonDocument("hello", 1), cancellationToken: token);
|
||
|
|
return hello.Contains("setName");
|
||
|
|
}
|
||
|
|
catch (MongoCommandException)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|