ZStandard Compression not working in MongoDB v4.2.7 - c#

Setup:
I'm using MongoDB v4.2.7 along with the .Net MongoDB driver v2.11.0(beta v) on a windows 10 machine.
Code
var mongoClientSettings = new MongoClientSettings();
mongoClientSettings.Compressors = new List<CompressorConfiguration>() {
new CompressorConfiguration(CompressorType.ZStandard)
};
var client = new MongoClient(mongoClientSettings);
IMongoDatabase testdb = client.GetDatabase("testdb");
var eaiRequestLogsCollection = testdb.GetCollection<EAIRequestsLogMDB>("EAIRequestsLogs");
eaiRequestLogsCollection.InsertMany(eAIRequestsLogMDBs);
Config
I've edited my mongod.cfg file as follows:
storage:
dbPath: C:\Program Files\MongoDB\Server\4.2\data
journal:
enabled: true
engine: "wiredTiger"
wiredTiger:
collectionConfig:
blockCompressor: "zstd"
Problem:
After the collection and the documents are added successfully I ran the db.printCollectionStats() on the mongo shell and I got block_compressor=snappy in the WiredTiger section while it should be block_compressor=zstd.
Below is a screenshot of the db.Stats(1024*1024*1024) output as well
"dataSize" : 0.08773485571146011 and "storageSize" : 0.009387969970703125

I posted a question on MongoDB Developer community Forums and was advised that my c# code was setting Network Compression rather than block_compressor.
This is the correct c# code that worked for me:
var client = new MongoClient("mongodb://127.0.0.1:27017");
IMongoDatabase testdb = client.GetDatabase("testdb");
testdb.CreateCollection("EAIRequestsLogs", new CreateCollectionOptions()
{
StorageEngine = new BsonDocument
{
{ "wiredTiger", new BsonDocument
{
{ "configString" , "block_compressor=zstd"}
}
}
}
});
var eaiRequestLogsCollection = testdb.GetCollection<EAIRequestsLogMDB>("EAIRequestsLogs");
Kind regards.

Related

How to connect to a cluster of sentinels using StackExchange.Redis?

Does Stackexchange.Redis (C#) support connecting to a cluster of sentinels for high availability with the latest version ? I'm finding it a bit odd how such an important feature of redis is not properly documented or practically no examples at all. Would appreciate any help.
You can see how to connect to sentinels by examining the tests of StackExchange.Redis. Specifically this one https://github.com/StackExchange/StackExchange.Redis/blob/master/tests/StackExchange.Redis.Tests/Sentinel.cs
Essentially the code you need to look at is here:
public Sentinel(ITestOutputHelper output) : base(output)
{
ConnectionLog = new StringWriter();
Skip.IfNoConfig(nameof(TestConfig.Config.SentinelServer), TestConfig.Current.SentinelServer);
Skip.IfNoConfig(nameof(TestConfig.Config.SentinelSeviceName), TestConfig.Current.SentinelSeviceName);
var options = new ConfigurationOptions()
{
CommandMap = CommandMap.Sentinel,
EndPoints = { { TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPort } },
AllowAdmin = true,
TieBreaker = "",
ServiceName = TestConfig.Current.SentinelSeviceName,
SyncTimeout = 5000
};
Conn = ConnectionMultiplexer.Connect(options, ConnectionLog);
Thread.Sleep(3000);
Assert.True(Conn.IsConnected);
Server = Conn.GetServer(TestConfig.Current.SentinelServer, TestConfig.Current.SentinelPort);
}
And then here:
[Fact]
public void SentinelGetMasterAddressByNameTest()
{
var endpoint = Server.SentinelGetMasterAddressByName(ServiceName);
Assert.NotNull(endpoint);
var ipEndPoint = endpoint as IPEndPoint;
Assert.NotNull(ipEndPoint);
Log("{0}:{1}", ipEndPoint.Address, ipEndPoint.Port);
}

No console output with MongoDB [duplicate]

This question already has answers here:
How do I log my queries in MongoDB C# Driver 2.0?
(3 answers)
Closed 4 years ago.
I have connected MongoDB to .NET and I'm trying to save data into the database. The program works fine and my data is inserted into the database, but my understanding from the documentation is that I should be able to see everything that is occurring in the console window as well. This is my sample program that I'm working on.
static void Main(string[] args)
{
MainAsync().Wait();
Console.ReadLine();
}
static async Task MainAsync()
{
var client = new MongoClient("mongodb://localhost:27017");
IMongoDatabase db = client.GetDatabase("machines");
var collection = db.GetCollection<BsonDocument>("cranes");
var document = new BsonDocument
{
{ "code", BsonValue.Create("0x657")},
{ "departments", new BsonArray(new[] {"Mech", "Forge"}) },
};
await collection.InsertOneAsync(document);
}
This is the console output I am seeing when running the program.
I can see that the data has been succesffully added in MongoDB Compass, but I do not have any feedback in the console window.
You need to initiate MongoClient by using MongoClientSettings instead, and subscribe for command events there.
var url = MongoUrl.Create("mongodb://localhost:27017");
var settings = MongoClientSettings.FromUrl(url);
settings.ClusterConfigurator += b => b.Subscribe<CommandStartedEvent>(
e => Console.WriteLine($"MongoDB: {e.Command.ToJson()}")
);
var client = new MongoClient(settings);
...

Xamarin IOS UIActivityViewController ExcludedActivityTypes how to include linked

I am trying to exclude Linkedin but when i checked UIActivityType Class, I found only below members.
AddToReadingList
AirDrop
AssignToContact
CopyToPasteboard
Mail
Message
OpenInIBooks
PostToFacebook
PostToFlickr
PostToTencentWeibo
PostToTwitter
PostToVimeo
Print
SaveToCameraRoll
Is there a way we can exclude linkedin?
Update:
I thought this radar concerning third-party values was closed, but it is still open :-(
http://openradar.appspot.com/20170408
...
The ExcludedActivityTypes is just an array of NSStrings that include the bundle id of the share extension. So use com.linkedin.LinkedIn.ShareExtension to exclude linkedin.
Example:
var activityItemsNSUrl = NSUrl.FromString("http://stackoverflow.com");
var activityItemsString = new NSString("StackOverflow");
var activityItems = new NSObject[] { activityItemsString, activityItemsNSUrl };
var activityViewController = new UIActivityViewController(activityItems, null)
{
ExcludedActivityTypes = new NSString[] {
UIActivityType.PostToVimeo,
new NSString("com.linkedin.LinkedIn.ShareExtension"),
UIActivityType.PostToFlickr
}
};
PresentViewController(activityViewController, true, () => { });
Re: https://developer.linkedin.com/docs/ios-sdk

How to copy mongo database with all it's collection using c# driver?

I am trying to copy a mongo database using copydb command using c# driver.
But it's just create the target db with no collection inside.
When i run the command directly with the mongo shell it work fine.
These is the c# code:
var db = mongo.GetServer().GetDatabase("admin");
var command = new CommandDocument(new BsonElement("copydb", 1),
new BsonElement("fromdb", "db1"),
new BsonElement("todb", "db2")
);
var result = db.RunCommand(command);
Its not copy the collections of db1.
These is the command i run into mongo shell and work fine:
db.runCommand({copydb:1, fromdb:"db1", todb:"db2"})
What am i missing?
Try following :
var result = db.RunCommand(
new CommandDocument(new BsonElement("copydb", 1),
new BsonElement("fromhost", "localhost"),
new BsonElement("fromdb", "sourcedb"),
new BsonElement("todb", "targetdb")));
Next code works. It's C# MongoDB.Driver 2.0
var database = mongoClient.GetDatabase("admin");
var command = #"{ copydb: 1, fromhost: 'localhost', fromdb: 'from', todb: 'toDbName'}";
await database.RunCommandAsync<BsonDocument>(BsonDocument.Parse(command));

Opening a MongoDB GridFS by name with C# Driver

In pymongo, there is an option to open a GridFS with a specific collection name. E.g. mygridfs = gridfs.GridFS(db, collection = mycolc).
I cannot find a similar option in the MongoDB C# driver (official MongoDB latest driver version).
As a result if I want to share GridFS data between Python and C# modules, I can only use the default GridFS in the DB (named 'fs').
Any clues to whether I can somehow access a GridFS with a non-default name in the C# MongoDB driver ?
A sample using grid in c#:
var url = new MongoUrl("mongodb://localhost");
var Client = new MongoClient(url);
var Server = Client.GetServer();
var Database = Server.GetDatabase("test");
var collection = Database.GetCollection("test");
var set = new MongoGridFSSettings {UpdateMD5 = true, ChunkSize = 512*1024, VerifyMD5 = false};
// you can set the name here
set.Root = "mycol";
var grid = Database.GetGridFS(set);
// Upload
grid.Upload(#"C:\Users\Hamid\Desktop\sample.txt", "remote");
// Download
grid.Download(#"C:\Users\Hamid\Desktop\sample2.txt", "remote");

Categories

Resources