11-02-2020 09:58 AM
Current I learn the MongoDB and try to combine into Labview.
First I download the labview driver from Mongo offical website. the .net version is 2.0.0.788. It is good to connect to local database and query and insert. But it doesn't support to connect Mongo Atlas(cloud). It will show mongodb+srv://.... string is invalid parameter.
So I browse the Mongo website that said it needs the driver higher than ver2.5 can support srv record. So I download the driver of 2.5.1 version. But it cannot find getdatabase method. So I search LV and find the root cause is LV not support generic type in load .net assembly.
I try to download mongo.driver.legacy.dll according to introduce. Then Getconnection, Getdatabase, List database and List collection is ok and feedback the database and collection names. But it meets erro when load Getcollection method. It is show invalid parameters.
So Does anyone know the detail reason?
11-02-2020 10:20 AM
The error show
Error 4 occurred at Invoke Node in test MongoDB.1vi.vi
Possible reason(s):
LabVIEW: (Hex 0x4) End of file encountered.
=========================
Invalid argument or arguments to function call.
Databasename and collectionname is feedback
11-03-2020 02:15 AM
C# testing is ok. Here is source code
using MongoDB.Bson;
using MongoDB.Driver;
class Connect
{
[Obsolete]
static void Main(string[] args)
{
var client = new MongoClient("mongodb+srv://username:password@host/test?authSource=admin&replicaSet=atlas-xkdq0z-shard-0&readPreference=primary&appname=MongoDB%20Compass&ssl=true");
var Server = client.GetServer();
var database = Server.GetDatabase("test");
var collection = database.GetCollection("weather");
var list = collection.FindAll();
foreach (var document in list)
{
Console.WriteLine(document["colour"]);
}
}
}