How to get the number of (open) MongoDB connections with the C# driver (1.9.0 NuGet package)?
MongoDB documentations describes that db.serverStatus() should give iformation about the count of open and available connections but I can't find any function in the C# driver which represents this information.
(Documentation of db.serverStatus(): http://docs.mongodb.org/manual/reference/command/serverStatus/ )
I searched my fork of the driver for serverStatus, there's no results, so currently, I don't think this command is supported.
There's no associated jira (with serverStatus, at least) that i can find
Adding this functionality would be fairly trivial I would think
Edit
I wrote on the mongodb driver google group, and got this reply from Craig at MongoDB inc.
You can simply run:
MongoDatabase adminDb = ...;
adminDb.RunCommand("serverStatus");
I believe this needs to be run on the admin database.
Related
I'm using MongoDB .net driver v2.10 and want to know, how I'm able to determine MongoDB version of connected MongoDB Atlas server, for example v4.2.5.
Thank you in advance for your support!
MongoDB database instance (IMongoDatabase interface in .NET) offers .runCommand() and you can run buildInfo to get server veresion:
var version = database.RunCommand(
new BsonDocumentCommand<BsonDocument>(new BsonDocument() {{"buildInfo", 1}}))
["version"];
The following is my codes to remove documents:
var filterAddInfo = builder.Lte("Claim_Date", branchEntity.Report_Date);
mongoDB.BranchPerformance.FindOneAndUpdate(
filterMain,
Builders<BsonDocument>.Update.PullFilter("Add_Info", filterAddInfo));
It's working with MongoDB, but it's not working if I connect to Azure MongoDB Api. It prompt:
Command findAndModify failed: Operator ''OPERATOR_PULL' with condition' is not supported..
Seems like condition (Eg. lte is not supported in Azure MongoDB Api). May I know is there any alternative way to change my codes cater for this condition?
We do not yet support the pull operator with a condition specified. Please reach out to askcosmosmongoapi [at] microsoft [dot] com with a sample document, and we'll be happy to work with you on a workaround.
As per title, I would like to request a calculation to a Spark cluster (local/HDInsight in Azure) and get the results back from a C# application.
I acknowledged the existence of Livy which I understand is a REST API application sitting on top of Spark to query it, and I have not found a standard C# API package. Is this the right tool for the job? Is it just missing a well known C# API?
The Spark cluster needs to access Azure Cosmos DB, therefore I need to be able to submit a job including the connector jar library (or its path on the cluster driver) in order for Spark to read data from Cosmos.
As a .NET Spark connector to query data did not seem to exist I wrote one
https://github.com/UnoSD/SparkSharp
It is just a quick implementation, but it does have also a way of querying Cosmos DB using Spark SQL
It's just a C# client for Livy but it should be more than enough.
using (var client = new HdInsightClient("clusterName", "admin", "password"))
using (var session = await client.CreateSessionAsync(config))
{
var sum = await session.ExecuteStatementAsync<int>("val res = 1 + 1\nprintln(res)");
const string sql = "SELECT id, SUM(json.total) AS total FROM cosmos GROUP BY id";
var cosmos = await session.ExecuteCosmosDbSparkSqlQueryAsync<IEnumerable<Result>>
(
"cosmosName",
"cosmosKey",
"cosmosDatabase",
"cosmosCollection",
"cosmosPreferredRegions",
sql
);
}
If your just looking for a way to query your spark cluster using SparkSql then this is a way to do it from C#:
https://github.com/Azure-Samples/hdinsight-dotnet-odbc-spark-sql/blob/master/Program.cs
The console app requires an ODBC driver installed. You can find that here:
https://www.microsoft.com/en-us/download/details.aspx?id=49883
Also the console app has a bug: add this line to the code after the part where the connection string is generated.
Immediately after this line:
connectionString = GetDefaultConnectionString();
Add this line
connectionString = connectionString + "DSN=Sample Microsoft Spark DSN";
If you change the name of the DSN when you install the spark ODBC Driver you will need to change the name in the above line then.
Since you need to access data from Cosmos DB, you could open a Jupyter Notebook on your cluster and ingest data into spark (create a permanent table of your data there) and then use this console app/your c# app to query that data.
If you have a spark job written in scala/python and need to submit it from a C# app then I guess LIVY is the best way to go. I am unsure if Mobius supports that.
Microsoft just released a dataframe based .NET support for Apache Spark via the .NET Foundation OSS. See http://dot.net/spark and http://github.com/dotnet/spark for more details. It is now available in HDInsight per default if you select the correct HDP/Spark version (currently 3.6 and 2.3, soon others as well).
UPDATE:
Long ago I said a clear no to this question.
However times has changed and Microsoft made an effort.
Pleas check out https://dotnet.microsoft.com/apps/data/spark
https://github.com/dotnet/spark
// Create a Spark session
var spark = SparkSession
.Builder()
.AppName("word_count_sample")
.GetOrCreate();
Writing spark applications in C# now is that easy!
OUTDATED:
No, C# is not the tool you should choose if you would like to work with Spark! However if you really want to do the job with it try as mentioned above Mobius
https://github.com/Microsoft/Mobius
Spark has 4 main languages and API-s for them: Scala, Java, Python, R.
If you are looking for a language in production I would not suggest the R API. The Other 3 work well.
For Cosmo DB connection I would suggest: https://github.com/Azure/azure-cosmosdb-spark
There is a function named "InStrRev" which is working fine in Access, but when I use that same function to get records in C# windows form then an error message pops up saying
Unidentified function 'InStrRev' in expression.
Is there some way that I can use this function, or is there some other function I can use in my Access query that gets the last index of any character from a field?
The older "Jet" driver for Access did not allow us to use VBA functions like InStrRev() in queries from external applications. Those functions would only be available to queries that were run from within Microsoft Access itself.
However, the OLEDB and ODBC drivers for the newer version of the Access Database Engine (a.k.a "ACE") do allow external applications to make use of many of those built-in VBA functions. So, if your application uses
Provider=Microsoft.Jet.OLEDB.4.0; (OLEDB), or
Driver={Microsoft Access Driver (*.mdb)}; (ODBC)
then the InStrRev() function will not work. However, if you use the newer "ACE" driver:
Provider=Microsoft.ACE.OLEDB.12.0; (OLEDB), or
Driver={Microsoft Access Driver (*.mdb, *.accdb)}; (ODBC)
then those same InStrRev() queries will run without error.
The newer version of the Access Database Engine (and drivers) is available as a free download here:
Microsoft Access Database Engine 2010 Redistributable
The equivalent method in .Net is String.LastIndexOf. You can use it as follows:
var str = "foo bar foo";
var lastIndexOfFoo = str.LastIndexOf("foo");
Using C# - I'm trying to find a list of all printers that are local and online (i.e. connected and ready to accept print requests)
I know the printer driver works - jobs will just wait until the printer is back online, but I need to find those specific that are online. These are clearly available to windows but the .net framework doesn't seem to accurately expose those which are currently online.
I'm trying to use lots of different methods and none seem to accurately work
// Get a list of available printers.
var printServer = new PrintServer();
var printQueues = printServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
foreach (PrintQueue printQueue in printQueues)
{
Console.WriteLine(printQueue.IsOffline); // This works for IsOffline, but doesn't tell us those that are online - and it's not an inverse relationship
}
very frustrating - any help appreciated.
Should add I'm using windows 8.1, and the solution should work also with win 7+
Edit:
So given the following collection of printers :
I would expect to see something along the lines of
Getting all Printers
Send To OneNote 2013 : Online
Pack1 : Offine
Microsoft XPS Document Writer : Online
Fax : Online
EPSONB12B28 (XP-412 413 415 Series) : Offine
Brother MFC-9970CDW Printer : Online
But they are ALWAYS reported as Online on any status I see
I have queried just about every conceivable windows device either by native driver or using Windows Management Instrumentation (WMI) classes.
To get you started, take a read of this article with C# source: http://www.codeproject.com/Articles/80680/Managing-Printers-Programatically-using-C-and-WMI
Also, not in C# but VB, some quick glance info on the same subject here: http://msdn.microsoft.com/en-us/library/aa394598(v=vs.85).aspx
Full WMI reference here: http://msdn.microsoft.com/en-us/library/aa394572(v=VS.85).aspx
Cheers and good luck!