generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented MongoDb server disable table scan option. (#23)
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using MongoDB.Bson; | ||
using MongoDB.Driver; | ||
|
||
namespace MongoDB.Extensions.Context | ||
{ | ||
public static class MongoServerExtensions | ||
{ | ||
public static void DisableTableScan(this IMongoClient mongoClient) | ||
{ | ||
var command = new BsonDocument { { "setParameter", 1 }, { "notablescan", 1 } }; | ||
|
||
mongoClient.GetDatabase("admin").RunCommand<BsonDocument>(command); | ||
} | ||
|
||
public static bool IsTableScanDisabled(this IMongoClient mongoClient) | ||
{ | ||
var getNoTableScanCommand = | ||
new BsonDocument { { "getParameter", 1 }, { "notablescan", 1 } }; | ||
|
||
BsonDocument parameterResult = mongoClient.GetDatabase("admin") | ||
.RunCommand<BsonDocument>(getNoTableScanCommand); | ||
|
||
BsonElement notablescanElement = parameterResult.GetElement("notablescan"); | ||
|
||
if(bool.TryParse(notablescanElement.Value.ToString(), out bool isDisabled)) | ||
{ | ||
return isDisabled; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |